Return error codes instead of exiting from Main()

This commit is contained in:
Ryan Cavicchioni 2021-01-16 10:36:07 -06:00
parent 4c6c3744c9
commit 2da3bcc2ff
Signed by: ryanc
GPG Key ID: 877EEDAF9245103D
2 changed files with 7 additions and 7 deletions

View File

@ -7,5 +7,5 @@ import (
)
func main() {
lumecmd.Main(os.Args)
os.Exit(lumecmd.Main(os.Args))
}

View File

@ -12,19 +12,19 @@ import (
const lumercFile string = ".lumerc"
func Main(args []string) {
func Main(args []string) int {
var config Config
configPath := getConfigPath()
if configPath == "" {
fmt.Println("fatal: ~/.lumerc was not found")
os.Exit(1)
return 1
}
if _, err := toml.DecodeFile(configPath, &config); err != nil {
fmt.Printf("fatal: failed to parse %s\n", configPath)
fmt.Println(err)
os.Exit(1)
return 1
}
envAccessToken := os.Getenv("LIFX_ACCESS_TOKEN")
@ -34,7 +34,7 @@ func Main(args []string) {
if config.AccessToken == "" {
fmt.Println("access token is not set")
os.Exit(1)
return 1
}
flag.Parse()
@ -51,7 +51,7 @@ func Main(args []string) {
cmd, ok := GetCommand(command)
if !ok {
fmt.Printf("lume: '%s' is not lume command. See 'lume help'\n", command)
os.Exit(1)
return 1
}
fs := cmd.Flags
fs.Parse(args[2:])
@ -61,7 +61,7 @@ func Main(args []string) {
if err != nil {
fmt.Fprintf(os.Stderr, "fatal: %s\n", err)
}
os.Exit(exitCode)
return exitCode
}
func getConfigPath() string {