Skip to content

Commit

Permalink
suppress error message by help (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
fxrlv authored May 28, 2021
1 parent 6693975 commit fc1a947
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions flagutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package flagutil
import (
"bytes"
"context"
"errors"
"flag"
"fmt"
"os"
Expand Down Expand Up @@ -75,7 +76,7 @@ func Parse(ctx context.Context, flags *flag.FlagSet, opts ...ParseOption) (err e
parse.AllowResetSpecified(fs, p.allowResetSpecified)

if err = p.Parse(ctx, fs); err != nil {
if err == flag.ErrHelp {
if errors.Is(err, flag.ErrHelp) {
_ = printUsageMaybe(ctx, &c, flags)
}
if err != nil {
Expand All @@ -85,7 +86,7 @@ func Parse(ctx context.Context, flags *flag.FlagSet, opts ...ParseOption) (err e
case flag.ContinueOnError:
return err
case flag.ExitOnError:
if err != flag.ErrHelp {
if !errors.Is(err, flag.ErrHelp) {
fmt.Fprintf(flags.Output(), "%v\n", err)
}
os.Exit(2)
Expand Down

0 comments on commit fc1a947

Please sign in to comment.