From 887903c0e104a39feadb4768adfa3cf37164994f Mon Sep 17 00:00:00 2001 From: sophia Date: Tue, 17 May 2022 14:05:34 -0500 Subject: [PATCH] Set aliases for command flags --- internal/cli/base.go | 5 ++++- internal/flags/flag.go | 3 --- internal/flags/group.go | 12 +++++++++++- plugins/commands/serve/type/command_arguments.rb | 2 +- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/internal/cli/base.go b/internal/cli/base.go index fbc93087a..f081743a3 100644 --- a/internal/cli/base.go +++ b/internal/cli/base.go @@ -388,6 +388,7 @@ 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", @@ -529,7 +530,9 @@ func (c *baseCommand) generateCliFlags(set []*component.CommandFlag) *flags.Set if f.ShortName != "" { opts = append(opts, flags.ShortName(rune(f.ShortName[0]))) } - + if len(f.Aliases) > 0 { + opts = append(opts, flags.Alias(f.Aliases...)) + } switch f.Type { case component.FlagBool: b, _ := strconv.ParseBool(f.DefaultValue) diff --git a/internal/flags/flag.go b/internal/flags/flag.go index 4e09fefdd..becea91eb 100644 --- a/internal/flags/flag.go +++ b/internal/flags/flag.go @@ -158,9 +158,6 @@ 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 df2c0333e..37e6ae177 100644 --- a/internal/flags/group.go +++ b/internal/flags/group.go @@ -260,7 +260,17 @@ func (g *Group) Display( } switch f.kind { case BooleanType: - opts[i] = fmt.Sprintf("%s --[no-]%s", opts[i], f.longName) + 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) + } case IncrementType: opts[i] = fmt.Sprintf("%s --%s", opts[i], f.longName) default: diff --git a/plugins/commands/serve/type/command_arguments.rb b/plugins/commands/serve/type/command_arguments.rb index a4fa4037e..8665005e0 100644 --- a/plugins/commands/serve/type/command_arguments.rb +++ b/plugins/commands/serve/type/command_arguments.rb @@ -52,7 +52,7 @@ module VagrantPlugins if v == true "--#{k}" elsif v == false - "--no-#{k}" + "--#{k}" else "--#{k}=#{v}" end