Skip to content

Commit

Permalink
Remove help flag from rest args
Browse files Browse the repository at this point in the history
Fixes #107.
  • Loading branch information
jessevdk committed Oct 18, 2015
1 parent 2e3d1bd commit 741647f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
17 changes: 17 additions & 0 deletions help_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,3 +391,20 @@ Help Options:
}
}
}

func TestHelpRestArgs(t *testing.T) {
opts := struct {
Verbose bool `short:"v"`
}{}

p := NewNamedParser("TestHelpDefaults", HelpFlag)
p.AddGroup("Application Options", "The application options", &opts)

retargs, err := p.ParseArgs([]string{"-h", "-v", "rest"})

if err == nil {
t.Fatalf("Expected help error")
}

assertStringArray(t, retargs, []string{"-v", "rest"})
}
10 changes: 9 additions & 1 deletion parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,15 @@ func (p *Parser) ParseArgs(args []string) ([]string, error) {
}

if reterr != nil {
return append([]string{s.arg}, s.args...), p.printError(reterr)
var retargs []string

if ourErr, ok := reterr.(*Error); !ok || ourErr.Type != ErrHelp {
retargs = append([]string{s.arg}, s.args...)
} else {
retargs = s.args
}

return retargs, p.printError(reterr)
}

return s.retargs, nil
Expand Down

0 comments on commit 741647f

Please sign in to comment.