diff --git a/internal/cli/base.go b/internal/cli/base.go index f081743a3..0dcc413de 100644 --- a/internal/cli/base.go +++ b/internal/cli/base.go @@ -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() } diff --git a/internal/flags/flag.go b/internal/flags/flag.go index becea91eb..4e09fefdd 100644 --- a/internal/flags/flag.go +++ b/internal/flags/flag.go @@ -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 } diff --git a/internal/flags/group.go b/internal/flags/group.go index 37e6ae177..df2c0333e 100644 --- a/internal/flags/group.go +++ b/internal/flags/group.go @@ -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: