1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
package cmd
const (
// ExSuccess is the exit code that signals that everything went as expected.
ExSuccess = 0
// ExUsage is the exit code that signals that the application was not started with the correct arguments.
ExUsage = 64
// ExUnavailable is the exit code that signals that the application failed to perform the intended task.
ExUnavailable = 69
// ExConfig is the exit code that signals that the task failed due to a configuration error.
ExConfig = 78
)
// Success is the empty Result that is used whenever the command ran successfully.
//
//nolint:errname
var Success = Result{}
// Result contains the final exit message and code for a CLI session.
//
//nolint:errname
type Result struct {
ExitCode int
Message string
}
func (e Result) Error() string {
return e.Message
}
// InvalidUsage returns a Result with the exit code ExUsage.
func InvalidUsage(message string) Result {
return Result{
ExUsage,
message,
}
}
// TaskUnavailable returns a Result with the exit code ExUnavailable.
func TaskUnavailable(message string) Result {
return Result{
ExUnavailable,
message,
}
}
// ConfigurationError returns a Result with the exit code ExConfig.
func ConfigurationError(message string) Result {
return Result{
ExConfig,
message,
}
}
|