Skip to content

Commit

Permalink
usage prints no errors if ExitOnError is true
Browse files Browse the repository at this point in the history
  • Loading branch information
alessio committed Oct 8, 2024
1 parent d58fcf3 commit d437d6a
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -952,17 +952,17 @@ func (f *FlagSet) usage() {
// --unknown arg ... (args will be arg ...)
func stripUnknownFlagValue(args []string) []string {
if len(args) == 0 {
//--unknown
// --unknown
return args
}

first := args[0]
if len(first) > 0 && first[0] == '-' {
//--unknown --next-flag ...
// --unknown --next-flag ...
return args
}

//--unknown arg ... (args will be arg ...)
// --unknown arg ... (args will be arg ...)
if len(args) > 1 {
return args[1:]
}
Expand Down Expand Up @@ -1164,7 +1164,10 @@ func (f *FlagSet) Parse(arguments []string) error {
case ContinueOnError:
return err
case ExitOnError:
fmt.Println(err)
if err == ErrHelp {
os.Exit(0)
}
fmt.Fprintln(os.Stderr, err)
os.Exit(2)
case PanicOnError:
panic(err)
Expand Down

0 comments on commit d437d6a

Please sign in to comment.