Encapsulate ExitCoder check into a lil func

This commit is contained in:
Dan Buch
2016-04-27 09:18:42 -04:00
parent f3e55a0783
commit f688d47415
3 changed files with 19 additions and 60 deletions

View File

@@ -2,6 +2,7 @@ package cli
import (
"fmt"
"os"
"strings"
)
@@ -49,3 +50,11 @@ func (ee *ExitError) String() string {
func (ee *ExitError) ExitCode() int {
return ee.exitCode
}
// HandleExitCoder checks if the error fulfills the ExitCoder interface, and if
// so calls os.Exit with the given exit code.
func HandleExitCoder(err error) {
if exitErr, ok := err.(ExitCoder); ok {
os.Exit(exitErr.ExitCode())
}
}