aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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")
}
}