Force all boolean flags to have a negative alias
This commit is contained in:
parent
28beec7bad
commit
d062e03d97
@ -88,8 +88,8 @@ type baseCommand struct {
|
||||
// flagTarget is the machine to target.
|
||||
flagTarget string
|
||||
|
||||
// flagNoTTY is whether the output is interactive
|
||||
flagNoTTY bool
|
||||
// flagTTY is whether the output is interactive
|
||||
flagTTY bool
|
||||
|
||||
// flagConnection contains manual flag-based connection info.
|
||||
flagConnection clicontext.Config
|
||||
@ -155,7 +155,7 @@ func BaseCommand(ctx context.Context, log hclog.Logger, logOutput io.Writer, opt
|
||||
// Set UI
|
||||
var ui terminal.UI
|
||||
// Set non interactive if the --no-tty flag is provided
|
||||
if bc.flagNoTTY {
|
||||
if !bc.flagTTY {
|
||||
ui = terminal.NonInteractiveUI(ctx)
|
||||
} else {
|
||||
// If no ui related flags are set, create a new one
|
||||
@ -286,7 +286,7 @@ func (c *baseCommand) Init(opts ...Option) (err error) {
|
||||
// Set UI
|
||||
var ui terminal.UI
|
||||
// Set non interactive if the --no-tty flag is provided
|
||||
if c.flagNoTTY {
|
||||
if !c.flagTTY {
|
||||
ui = terminal.NonInteractiveUI(c.Ctx)
|
||||
} else {
|
||||
// If no ui related flags are set, use the base config ui
|
||||
@ -388,7 +388,6 @@ func (c *baseCommand) flagSet(bit flagSetBit, f func([]*component.CommandFlag) [
|
||||
Description: "Can be used to disable colored output",
|
||||
DefaultValue: "true",
|
||||
Type: component.FlagBool,
|
||||
Aliases: []string{"no-color"},
|
||||
},
|
||||
{
|
||||
LongName: "basis",
|
||||
@ -403,9 +402,9 @@ func (c *baseCommand) flagSet(bit flagSetBit, f func([]*component.CommandFlag) [
|
||||
Type: component.FlagString,
|
||||
},
|
||||
{
|
||||
LongName: "no-tty",
|
||||
LongName: "tty",
|
||||
Description: "Enable non-interactive output",
|
||||
DefaultValue: "false",
|
||||
DefaultValue: "true",
|
||||
Type: component.FlagBool,
|
||||
},
|
||||
}
|
||||
@ -492,8 +491,8 @@ func (c *baseCommand) Parse(
|
||||
}
|
||||
case "remote":
|
||||
c.flagRemote = pf.DefaultValue().(bool)
|
||||
case "no-tty":
|
||||
c.flagNoTTY = pf.DefaultValue().(bool)
|
||||
case "tty":
|
||||
c.flagTTY = pf.DefaultValue().(bool)
|
||||
}
|
||||
if !pf.Updated() {
|
||||
continue
|
||||
@ -508,8 +507,8 @@ func (c *baseCommand) Parse(
|
||||
c.flagTarget = pf.Value().(string)
|
||||
case "remote":
|
||||
c.flagRemote = pf.Value().(bool)
|
||||
case "no-tty":
|
||||
c.flagNoTTY = !pf.Value().(bool)
|
||||
case "tty":
|
||||
c.flagTTY = pf.Value().(bool)
|
||||
}
|
||||
c.flagData[f] = pf.Value()
|
||||
}
|
||||
|
||||
@ -158,6 +158,9 @@ func newFlag(
|
||||
for _, fn := range modifiers {
|
||||
fn(f)
|
||||
}
|
||||
if kind == BooleanType {
|
||||
Alias(fmt.Sprintf("no-%s", f.longName))(f)
|
||||
}
|
||||
|
||||
return f
|
||||
}
|
||||
|
||||
@ -260,17 +260,7 @@ func (g *Group) Display(
|
||||
}
|
||||
switch f.kind {
|
||||
case BooleanType:
|
||||
foundNoAlias := false
|
||||
for _, a := range f.aliases {
|
||||
if a == fmt.Sprintf("no-%s", f.longName) {
|
||||
foundNoAlias = true
|
||||
opts[i] = fmt.Sprintf("%s --[no-]%s", opts[i], f.longName)
|
||||
break
|
||||
}
|
||||
}
|
||||
if !foundNoAlias {
|
||||
opts[i] = fmt.Sprintf("%s --%s", opts[i], f.longName)
|
||||
}
|
||||
opts[i] = fmt.Sprintf("%s --[no-]%s", opts[i], f.longName)
|
||||
case IncrementType:
|
||||
opts[i] = fmt.Sprintf("%s --%s", opts[i], f.longName)
|
||||
default:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user