Skip to content

Commit

Permalink
Fail immediately if there's a getopt parse error (#30)
Browse files Browse the repository at this point in the history
The getopt code doesn't appear to fully respect ErrorHandling so
unrecognized flags result in Usage being displayed but not an Exit().

https://github.com/rsc/getopt/blob/20be20937449f18bb9967c10d732849fb4401e63/getopt.go#L274-L277

In our application, this was causing Usage to be displayed twice.

To fix this, we catch the lower-level Parse() error and bail
immediately.
  • Loading branch information
jparise authored Aug 27, 2021
1 parent dae9dc7 commit 0509bac
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ func lint(l *thriftcheck.Linter, filenames []string) (thriftcheck.Messages, erro

func main() {
// Parse command line flags
getopt.Parse()
if err := getopt.CommandLine.Parse(os.Args[1:]); err != nil {
os.Exit(1 << uint(thriftcheck.Error))
}
if *helpFlag {
flag.Usage()
os.Exit(0)
Expand Down

0 comments on commit 0509bac

Please sign in to comment.