diff --git a/app_test.go b/app_test.go index 9a09405..28f96a6 100644 --- a/app_test.go +++ b/app_test.go @@ -249,6 +249,24 @@ func TestApp_CommandWithFlagBeforeTerminator(t *testing.T) { expect(t, args[2], "--notARealFlag") } +func TestApp_CommandWithDash(t *testing.T) { + var args []string + + app := NewApp() + command := Command{ + Name: "cmd", + Action: func(c *Context) { + args = c.Args() + }, + } + app.Commands = []Command{command} + + app.Run([]string{"", "cmd", "my-arg", "-"}) + + expect(t, args[0], "my-arg") + expect(t, args[1], "-") +} + func TestApp_CommandWithNoFlagBeforeTerminator(t *testing.T) { var args []string diff --git a/command.go b/command.go index e42178e..aebb4bb 100644 --- a/command.go +++ b/command.go @@ -81,6 +81,9 @@ func (c Command) Run(ctx *Context) (err error) { if arg == "--" { terminatorIndex = index break + } else if arg == "-" { + // Do nothing. A dash alone is not really a flag. + continue } else if strings.HasPrefix(arg, "-") && firstFlagIndex == -1 { firstFlagIndex = index }