aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteven Roose <[email protected]>2017-10-20 13:06:17 +0200
committerAlbert Nigmatzianov <[email protected]>2017-10-20 13:06:17 +0200
commit97afa5e7ca8a08a383cb259e06636b5e2cc7897f (patch)
tree6b17fe97f4bd89a8ddeb415c6012893d6656465e
parent1f33b80956cde38911d1f23d764deb8d77a649ce (diff)
Prevent printing when using ContinueOnError (#144)
-rw-r--r--flag.go7
-rw-r--r--flag_test.go4
2 files changed, 7 insertions, 4 deletions
diff --git a/flag.go b/flag.go
index 187e4c9..73c237b 100644
--- a/flag.go
+++ b/flag.go
@@ -873,8 +873,10 @@ func VarP(value Value, name, shorthand, usage string) {
// returns the error.
func (f *FlagSet) failf(format string, a ...interface{}) error {
err := fmt.Errorf(format, a...)
- fmt.Fprintln(f.out(), err)
- f.usage()
+ if f.errorHandling != ContinueOnError {
+ fmt.Fprintln(f.out(), err)
+ f.usage()
+ }
return err
}
@@ -1056,6 +1058,7 @@ func (f *FlagSet) Parse(arguments []string) error {
case ContinueOnError:
return err
case ExitOnError:
+ fmt.Println(err)
os.Exit(2)
case PanicOnError:
panic(err)
diff --git a/flag_test.go b/flag_test.go
index f2d6f28..d587752 100644
--- a/flag_test.go
+++ b/flag_test.go
@@ -106,8 +106,8 @@ func TestUsage(t *testing.T) {
if GetCommandLine().Parse([]string{"--x"}) == nil {
t.Error("parse did not fail for unknown flag")
}
- if !called {
- t.Error("did not call Usage for unknown flag")
+ if called {
+ t.Error("did call Usage while using ContinueOnError")
}
}