Add helper method to exit with error code

This commit is contained in:
Ryan Cavicchioni 2021-01-20 23:09:58 -06:00
parent c3495ac57a
commit 8364201d7b
Signed by: ryanc
GPG Key ID: 877EEDAF9245103D
2 changed files with 10 additions and 7 deletions

View File

@ -1,16 +1,11 @@
package main package main
import ( import (
"fmt"
"os" "os"
lumecmd "git.kill0.net/chill9/lume/cmd" lumecmd "git.kill0.net/chill9/lume/cmd"
) )
func main() { func main() {
exitCode, err := lumecmd.Main(os.Args) lumecmd.ExitWithCode(lumecmd.Main(os.Args))
if err != nil { }
fmt.Fprintf(os.Stderr, "%s\n", err)
}
os.Exit(exitCode)
}

View File

@ -2,6 +2,7 @@ package lumecmd
import ( import (
"fmt" "fmt"
"os"
"sort" "sort"
"strconv" "strconv"
"strings" "strings"
@ -151,3 +152,10 @@ func sortResults(res []lifx.Result) {
return res[i].Label < res[j].Label 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)
}