-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Skip exit code 1 for 'help' output (#689)
* skip help error output * rename error type
- Loading branch information
1 parent
8bbc210
commit 3c5384c
Showing
4 changed files
with
67 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package errors | ||
|
||
import ( | ||
"io" | ||
|
||
"github.com/fastly/cli/pkg/text" | ||
) | ||
|
||
// SkipExitError is an error that can cause the os.Exit(1) to be skipped. | ||
// An example is 'help' output (e.g. --help). | ||
type SkipExitError struct { | ||
Skip bool | ||
Err error | ||
} | ||
|
||
// Unwrap returns the inner error. | ||
func (ee SkipExitError) Unwrap() error { | ||
return ee.Err | ||
} | ||
|
||
// Error prints the inner error string. | ||
func (ee SkipExitError) Error() string { | ||
if ee.Err == nil { | ||
return "" | ||
} | ||
return ee.Err.Error() | ||
} | ||
|
||
// Print the error to the io.Writer for human consumption. | ||
// The inner error is always printed via text.Output with an "Error: " prefix | ||
// and a "." suffix. | ||
func (ee SkipExitError) Print(w io.Writer) { | ||
if ee.Err != nil { | ||
text.Error(w, "%s.", ee.Err.Error()) | ||
} | ||
} |