-
Couldn't load subscription status.
- Fork 1.8k
Closed
Description
if a Command is invoked as cli cmd arg1 -f arg2 where -f is a BoolFlag the result of ctx.Args() in the command function will be [arg2 arg1].
This appears to be related to #36
I have made the test case below (which currrently fails), but I am not really able to find a decent fix.
func TestApp_CommandWithBoolFlagAfterArgs(t *testing.T) {
var args []string
app := cli.NewApp()
command := cli.Command{
Name: "cmd",
Flags: []cli.Flag{
cli.BoolFlag{
Name: "f",
Usage: "foo",
},
},
Action: func(c *cli.Context) {
args = c.Args()
},
}
app.Commands = []cli.Command{command}
app.Run([]string{"", "cmd", "1", "2", "-f", "3"})
expect := []string{"1", "2", "3"}
if !reflect.DeepEqual(args, expect) {
t.Errorf("Got %v (type %T) - expected %v (type %T)", args, args, expect, expect)
}
}
Fails with
app_test.go:216: Got [3 1 2] (type []string) - expected [1 2 3] (type []string)
Hope you can come up with something good.
Metadata
Metadata
Assignees
Labels
No labels