Move error types to errors.go

This commit is contained in:
Dan Buch 2016-04-27 09:13:52 -04:00
parent b7329f4968
commit f3e55a0783
No known key found for this signature in database
GPG Key ID: FAEF12936DD3E3EC
2 changed files with 51 additions and 50 deletions

50
cli.go
View File

@ -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
}

51
errors.go Normal file
View File

@ -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
}