Skip to content

Commit 0509bac

Browse files
authored
Fail immediately if there's a getopt parse error (#30)
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.
1 parent dae9dc7 commit 0509bac

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

cmd/main.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,9 @@ func lint(l *thriftcheck.Linter, filenames []string) (thriftcheck.Messages, erro
127127

128128
func main() {
129129
// Parse command line flags
130-
getopt.Parse()
130+
if err := getopt.CommandLine.Parse(os.Args[1:]); err != nil {
131+
os.Exit(1 << uint(thriftcheck.Error))
132+
}
131133
if *helpFlag {
132134
flag.Usage()
133135
os.Exit(0)

0 commit comments

Comments
 (0)