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