Set aliases for command flags
This commit is contained in:
parent
584e7d2913
commit
887903c0e1
@ -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)
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -260,7 +260,17 @@ 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)
|
||||
}
|
||||
case IncrementType:
|
||||
opts[i] = fmt.Sprintf("%s --%s", opts[i], f.longName)
|
||||
default:
|
||||
|
||||
@ -52,7 +52,7 @@ module VagrantPlugins
|
||||
if v == true
|
||||
"--#{k}"
|
||||
elsif v == false
|
||||
"--no-#{k}"
|
||||
"--#{k}"
|
||||
else
|
||||
"--#{k}=#{v}"
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user