Skip to content

Commit

Permalink
Show how to exit(0) on --help in example
Browse files Browse the repository at this point in the history
  • Loading branch information
jessevdk committed Nov 4, 2016
1 parent e1bd227 commit 8bc97d6
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion examples/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ var parser = flags.NewParser(&options, flags.Default)

func main() {
if _, err := parser.Parse(); err != nil {
os.Exit(1)
if flagsErr, ok := err.(*flags.Error); ok && flagsErr.Type == flags.ErrHelp {
os.Exit(0)
} else {
os.Exit(1)
}
}
}

0 comments on commit 8bc97d6

Please sign in to comment.