Combine bool short names

Adds the ability to allow the combination of bool
short-name options.  For example,

cmd foobar -ov

This is done through a bool "UseShortOptionHandler" set in
the command struct.

Built upon PR #621

Signed-off-by: baude <bbaude@redhat.com>
This commit is contained in:
baude
2017-11-13 15:28:23 -06:00
parent 43c8c02cf5
commit fd5382e7a5
4 changed files with 82 additions and 26 deletions

View File

@@ -1048,6 +1048,31 @@ func TestParseMultiBool(t *testing.T) {
a.Run([]string{"run", "--serve"})
}
func TestParseBoolShortOptionHandle(t *testing.T) {
a := App{
Commands: []Command{
{
Name: "foobar",
UseShortOptionHandling: true,
Action: func(ctx *Context) error {
if ctx.Bool("serve") != true {
t.Errorf("main name not set")
}
if ctx.Bool("option") != true {
t.Errorf("short name not set")
}
return nil
},
Flags: []Flag{
BoolFlag{Name: "serve, s"},
BoolFlag{Name: "option, o"},
},
},
},
}
a.Run([]string{"run", "foobar", "-so"})
}
func TestParseDestinationBool(t *testing.T) {
var dest bool
a := App{