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",
|
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",
|
||||||
@ -529,7 +530,9 @@ func (c *baseCommand) generateCliFlags(set []*component.CommandFlag) *flags.Set
|
|||||||
if f.ShortName != "" {
|
if f.ShortName != "" {
|
||||||
opts = append(opts, flags.ShortName(rune(f.ShortName[0])))
|
opts = append(opts, flags.ShortName(rune(f.ShortName[0])))
|
||||||
}
|
}
|
||||||
|
if len(f.Aliases) > 0 {
|
||||||
|
opts = append(opts, flags.Alias(f.Aliases...))
|
||||||
|
}
|
||||||
switch f.Type {
|
switch f.Type {
|
||||||
case component.FlagBool:
|
case component.FlagBool:
|
||||||
b, _ := strconv.ParseBool(f.DefaultValue)
|
b, _ := strconv.ParseBool(f.DefaultValue)
|
||||||
|
|||||||
@ -158,9 +158,6 @@ 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,7 +260,17 @@ func (g *Group) Display(
|
|||||||
}
|
}
|
||||||
switch f.kind {
|
switch f.kind {
|
||||||
case BooleanType:
|
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:
|
case IncrementType:
|
||||||
opts[i] = fmt.Sprintf("%s --%s", opts[i], f.longName)
|
opts[i] = fmt.Sprintf("%s --%s", opts[i], f.longName)
|
||||||
default:
|
default:
|
||||||
|
|||||||
@ -52,7 +52,7 @@ module VagrantPlugins
|
|||||||
if v == true
|
if v == true
|
||||||
"--#{k}"
|
"--#{k}"
|
||||||
elsif v == false
|
elsif v == false
|
||||||
"--no-#{k}"
|
"--#{k}"
|
||||||
else
|
else
|
||||||
"--#{k}=#{v}"
|
"--#{k}=#{v}"
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user