Update docs and tests around cli.Exit

Some of the docs were lacking or incomplete concerning how to properly
use cli.Exit, cli.HandleExitCoder, and the ExitErrHandler field on cli.App.
This change aims to clarify the usage of those pieces.

I also noticed that we have two identical functions now: cli.Exit and
cli.NewExitError. Since the latter seems to be more recent and less well
documented, I went ahead and marked it as deprecated so that we can keep
our public interface small.

Also added a missing test case for behavior that's been around a while
but was not documented or tested.

Related: #1089
This commit is contained in:
Robert Liebowitz
2020-03-24 20:32:39 -04:00
parent 1c4bb12e86
commit 959cf9de8a
3 changed files with 42 additions and 11 deletions

View File

@@ -67,6 +67,26 @@ func TestHandleExitCoder_MultiErrorWithExitCoder(t *testing.T) {
expect(t, called, true)
}
func TestHandleExitCoder_MultiErrorWithoutExitCoder(t *testing.T) {
exitCode := 0
called := false
OsExiter = func(rc int) {
if !called {
exitCode = rc
called = true
}
}
defer func() { OsExiter = fakeOsExiter }()
err := newMultiError(errors.New("wowsa"), errors.New("egad"))
HandleExitCoder(err)
expect(t, exitCode, 1)
expect(t, called, true)
}
// make a stub to not import pkg/errors
type ErrorWithFormat struct {
error