Merge pull request #323 from hpcloud/master
Fixed mishandling of a "-"(dash)-argument causing reordering of cli n…
This commit is contained in:
commit
cf1f63a727
18
app_test.go
18
app_test.go
@ -249,6 +249,24 @@ func TestApp_CommandWithFlagBeforeTerminator(t *testing.T) {
|
|||||||
expect(t, args[2], "--notARealFlag")
|
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) {
|
func TestApp_CommandWithNoFlagBeforeTerminator(t *testing.T) {
|
||||||
var args []string
|
var args []string
|
||||||
|
|
||||||
|
@ -81,6 +81,9 @@ func (c Command) Run(ctx *Context) (err error) {
|
|||||||
if arg == "--" {
|
if arg == "--" {
|
||||||
terminatorIndex = index
|
terminatorIndex = index
|
||||||
break
|
break
|
||||||
|
} else if arg == "-" {
|
||||||
|
// Do nothing. A dash alone is not really a flag.
|
||||||
|
continue
|
||||||
} else if strings.HasPrefix(arg, "-") && firstFlagIndex == -1 {
|
} else if strings.HasPrefix(arg, "-") && firstFlagIndex == -1 {
|
||||||
firstFlagIndex = index
|
firstFlagIndex = index
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user