Skip to content

Commit 80b6daf

Browse files
authored
fix: Stop printing "pflag: help requested" when asked for help. (#95)
1 parent 3743a86 commit 80b6daf

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

main.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package main
1717

1818
import (
19+
"errors"
1920
"fmt"
2021
"os"
2122
"path"
@@ -30,6 +31,8 @@ import (
3031
)
3132

3233
func main() {
34+
flag.CommandLine.Init(os.Args[0], flag.ContinueOnError)
35+
3336
c := &cmd.Config{}
3437
c.FromFlags(nil)
3538
logLevel := flag.CountP("verbose", "v", "Log more verbosely")
@@ -48,7 +51,12 @@ func main() {
4851
flag.PrintDefaults()
4952
}
5053

51-
flag.Parse()
54+
if err := flag.CommandLine.Parse(os.Args[1:]); err != nil {
55+
if !errors.Is(err, flag.ErrHelp) {
56+
fmt.Fprintln(os.Stderr, err)
57+
}
58+
os.Exit(2)
59+
}
5260

5361
if *version {
5462
fmt.Fprintln(os.Stdout, readVersion())

0 commit comments

Comments
 (0)