From 8364201d7bbe4ab6d69467d92963c65146575b59 Mon Sep 17 00:00:00 2001 From: Ryan Cavicchioni Date: Wed, 20 Jan 2021 23:09:58 -0600 Subject: [PATCH] Add helper method to exit with error code --- cmd/lume/main.go | 9 ++------- cmd/util.go | 8 ++++++++ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/cmd/lume/main.go b/cmd/lume/main.go index f22f9d9..4f21b8b 100644 --- a/cmd/lume/main.go +++ b/cmd/lume/main.go @@ -1,16 +1,11 @@ package main import ( - "fmt" "os" lumecmd "git.kill0.net/chill9/lume/cmd" ) func main() { - exitCode, err := lumecmd.Main(os.Args) - if err != nil { - fmt.Fprintf(os.Stderr, "%s\n", err) - } - os.Exit(exitCode) -} + lumecmd.ExitWithCode(lumecmd.Main(os.Args)) +} \ No newline at end of file diff --git a/cmd/util.go b/cmd/util.go index ebba208..445eadf 100644 --- a/cmd/util.go +++ b/cmd/util.go @@ -2,6 +2,7 @@ package lumecmd import ( "fmt" + "os" "sort" "strconv" "strings" @@ -151,3 +152,10 @@ func sortResults(res []lifx.Result) { return res[i].Label < res[j].Label }) } + +func ExitWithCode(code int, err error) { + if err != nil { + fmt.Fprintf(os.Stderr, "%s\n", err) + } + os.Exit(code) +}