Refactor CLI exit code and error handling

This commit is contained in:
2021-01-17 21:08:13 -06:00
parent 5cc5be7846
commit e024b45e0a
11 changed files with 47 additions and 35 deletions

View File

@ -81,17 +81,17 @@ func SetColorCmd(args CmdArgs) (int, error) {
} else if rgbFlag != "" {
color, err := parseRGB(rgbFlag)
if err != nil {
return 1, err
return ExitError, err
}
state.Color = color
} else if name != "" {
hsb, ok := args.Config.Colors[name]
if !ok {
return 1, fmt.Errorf("%s is not a defined color", name)
return ExitError, fmt.Errorf("%s is not a defined color", name)
}
color, err := lifx.NewHSBColor(hsb[0], hsb[1], hsb[2])
if err != nil {
return 1, err
return ExitError, err
}
state.Color = color
}
@ -111,12 +111,12 @@ func SetColorCmd(args CmdArgs) (int, error) {
r, err := c.SetState(selector, state)
if err != nil {
fmt.Printf("fatal: %s\n", err)
return 1, err
return ExitError, err
}
if !fast {
PrintResults(r.Results)
}
return 0, nil
return ExitSuccess, nil
}