diff --git a/help_test.go b/help_test.go index 01792ea..e31ac25 100644 --- a/help_test.go +++ b/help_test.go @@ -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"}) +} diff --git a/parser.go b/parser.go index 928f225..df753ca 100644 --- a/parser.go +++ b/parser.go @@ -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