-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: ExitException to handle full range of valid exit codes (#20)
- Loading branch information
1 parent
338dff8
commit 47752dc
Showing
4 changed files
with
23 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,21 @@ | ||
enum ExitCodeType { | ||
/// An exception that can be thrown to exit the command with a specific exit code. | ||
class ExitException implements Exception { | ||
/// Successful termination - The command was successful. | ||
static const int codeOk = 0; | ||
|
||
/// General errors - This code is often used to indicate generic or | ||
/// unspecified errors. | ||
general(1), | ||
|
||
/// Command invoked cannot execute - The specified command was found but | ||
/// couldn't be executed. | ||
commandInvokedCannotExecute(126), | ||
|
||
/// Command not found - The specified command was not found or couldn't be | ||
/// located. | ||
commandNotFound(127); | ||
static const int codeError = 1; | ||
|
||
const ExitCodeType(this.exitCode); | ||
/// The exit code to use. | ||
final int exitCode; | ||
} | ||
|
||
/// An exception that can be thrown to exit the command with a specific exit | ||
class ExitException implements Exception { | ||
/// Creates an instance of [ExitException]. | ||
ExitException([this.exitCodeType = ExitCodeType.general]); | ||
/// Creates an instance of [ExitException] with a given exit code. | ||
ExitException(this.exitCode); | ||
|
||
/// The type of exit code to use. | ||
final ExitCodeType exitCodeType; | ||
/// Creates an instance of [ExitException] with an OK exit code (0). | ||
ExitException.ok() : exitCode = codeOk; | ||
|
||
/// The exit code to use. | ||
int get exitCode => exitCodeType.exitCode; | ||
/// Creates an instance of [ExitException] with a general error exit code (1). | ||
ExitException.error() : exitCode = codeError; | ||
} |
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