From f3e55a07831afc7b4ccaf13f31b2baa1bc55fac3 Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Wed, 27 Apr 2016 09:13:52 -0400 Subject: [PATCH] Move error types to errors.go --- cli.go | 50 -------------------------------------------------- errors.go | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 50 deletions(-) create mode 100644 errors.go diff --git a/cli.go b/cli.go index f8476d2..b742545 100644 --- a/cli.go +++ b/cli.go @@ -17,53 +17,3 @@ // app.Run(os.Args) // } package cli - -import ( - "fmt" - "strings" -) - -type MultiError struct { - Errors []error -} - -func NewMultiError(err ...error) MultiError { - return MultiError{Errors: err} -} - -func (m MultiError) Error() string { - errs := make([]string, len(m.Errors)) - for i, err := range m.Errors { - errs[i] = err.Error() - } - - return strings.Join(errs, "\n") -} - -type ExitCoder interface { - ExitCode() int -} - -type ExitError struct { - exitCode int - message string -} - -func NewExitError(message string, exitCode int) *ExitError { - return &ExitError{ - exitCode: exitCode, - message: message, - } -} - -func (ee *ExitError) Error() string { - return ee.message -} - -func (ee *ExitError) String() string { - return fmt.Sprintf("%s exitcode=%v", ee.message, ee.exitCode) -} - -func (ee *ExitError) ExitCode() int { - return ee.exitCode -} diff --git a/errors.go b/errors.go new file mode 100644 index 0000000..0c6b44d --- /dev/null +++ b/errors.go @@ -0,0 +1,51 @@ +package cli + +import ( + "fmt" + "strings" +) + +type MultiError struct { + Errors []error +} + +func NewMultiError(err ...error) MultiError { + return MultiError{Errors: err} +} + +func (m MultiError) Error() string { + errs := make([]string, len(m.Errors)) + for i, err := range m.Errors { + errs[i] = err.Error() + } + + return strings.Join(errs, "\n") +} + +type ExitCoder interface { + ExitCode() int +} + +type ExitError struct { + exitCode int + message string +} + +func NewExitError(message string, exitCode int) *ExitError { + return &ExitError{ + exitCode: exitCode, + message: message, + } +} + +func (ee *ExitError) Error() string { + return ee.message +} + +func (ee *ExitError) String() string { + return fmt.Sprintf("%s exitcode=%v", ee.message, ee.exitCode) +} + +func (ee *ExitError) ExitCode() int { + return ee.exitCode +}