From 3d9e153c0cd673fae3bcc403bbcff52db72777b1 Mon Sep 17 00:00:00 2001 From: Carl Johnson Date: Fri, 2 Oct 2020 10:11:24 -0400 Subject: [PATCH] Go 1.15 changed the exit code for --help https://github.com/golang/go/issues/37533 I am Hyrum https://www.hyrumslaw.com --- code.go | 5 ++--- code_test.go | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/code.go b/code.go index e7c75af..b456220 100644 --- a/code.go +++ b/code.go @@ -14,9 +14,8 @@ type Coder interface { // Get gets the exit code associated with an error. Cases: // -// nil => 0 +// nil or flag.ErrHelp => 0 // errors implementing Coder => value returned by ExitCode -// flag.ErrHelp => 2 // all other errors => 1 func Get(err error) int { if err == nil { @@ -28,7 +27,7 @@ func Get(err error) int { } if errors.Is(err, flag.ErrHelp) { - return 2 + return 0 } return 1 diff --git a/code_test.go b/code_test.go index bf963ef..071540d 100644 --- a/code_test.go +++ b/code_test.go @@ -19,7 +19,7 @@ func TestGet(t *testing.T) { }{ "nil": {nil, 0}, "default": {errors.New(""), 1}, - "help": {flag.ErrHelp, 2}, + "help": {flag.ErrHelp, 0}, "set": {exitcode.Set(errors.New(""), 3), 3}, "wrapped": {wrapped, 4}, }