Skip to content

Commit

Permalink
Go 1.15 changed the exit code for --help
Browse files Browse the repository at this point in the history
  • Loading branch information
earthboundkid committed Oct 2, 2020
1 parent 670ac0c commit 3d9e153
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
5 changes: 2 additions & 3 deletions code.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -28,7 +27,7 @@ func Get(err error) int {
}

if errors.Is(err, flag.ErrHelp) {
return 2
return 0
}

return 1
Expand Down
2 changes: 1 addition & 1 deletion code_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
}
Expand Down

0 comments on commit 3d9e153

Please sign in to comment.