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

View File

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