ExitFailure matches stdlib.h

This commit is contained in:
Ryan Cavicchioni 2021-01-31 11:08:24 -06:00
parent ec673a6fde
commit 320815293d
Signed by: ryanc
GPG Key ID: 877EEDAF9245103D
9 changed files with 18 additions and 18 deletions

View File

@ -11,7 +11,7 @@ import (
const ( const (
ExitSuccess = iota ExitSuccess = iota
ExitError ExitFailure
) )
type Config struct { type Config struct {

View File

@ -23,7 +23,7 @@ func LsCmd(args CmdArgs) (int, error) {
selector := args.Flags.String("selector") selector := args.Flags.String("selector")
lights, err := c.ListLights(selector) lights, err := c.ListLights(selector)
if err != nil { if err != nil {
return ExitError, err return ExitFailure, err
} }
PrintLights(lights) PrintLights(lights)
return ExitSuccess, nil return ExitSuccess, nil

View File

@ -20,12 +20,12 @@ func Main(args []string) (int, error) {
configPath := getConfigPath() configPath := getConfigPath()
if configPath == "" { if configPath == "" {
err = errors.New("fatal: ~/.lumerc was not found") err = errors.New("fatal: ~/.lumerc was not found")
return ExitError, err return ExitFailure, err
} }
if _, err := toml.DecodeFile(configPath, &config); err != nil { if _, err := toml.DecodeFile(configPath, &config); err != nil {
err = fmt.Errorf("fatal: failed to parse %s; %w", configPath, err) err = fmt.Errorf("fatal: failed to parse %s; %w", configPath, err)
return ExitError, err return ExitFailure, err
} }
envAccessToken := os.Getenv("LIFX_ACCESS_TOKEN") envAccessToken := os.Getenv("LIFX_ACCESS_TOKEN")
@ -34,7 +34,7 @@ func Main(args []string) (int, error) {
} }
if err = config.Validate(); err != nil { if err = config.Validate(); err != nil {
return ExitError, fmt.Errorf("fatal: %s", err) return ExitFailure, fmt.Errorf("fatal: %s", err)
} }
flag.Parse() flag.Parse()
@ -51,7 +51,7 @@ func Main(args []string) (int, error) {
cmd, ok := GetCommand(command) cmd, ok := GetCommand(command)
if !ok { if !ok {
err = fmt.Errorf("lume: '%s' is not lume command. See 'lume help'", command) err = fmt.Errorf("lume: '%s' is not lume command. See 'lume help'", command)
return ExitError, err return ExitFailure, err
} }
fs := cmd.Flags fs := cmd.Flags
fs.Parse(args[2:]) fs.Parse(args[2:])

View File

@ -33,7 +33,7 @@ func PoweroffCmd(args CmdArgs) (int, error) {
r, err := c.SetState(selector, state) r, err := c.SetState(selector, state)
if err != nil { if err != nil {
return ExitError, err return ExitFailure, err
} }
PrintResults(r.Results) PrintResults(r.Results)
return ExitSuccess, nil return ExitSuccess, nil

View File

@ -33,7 +33,7 @@ func PoweronCmd(args CmdArgs) (int, error) {
r, err := c.SetState(selector, state) r, err := c.SetState(selector, state)
if err != nil { if err != nil {
return ExitError, err return ExitFailure, err
} }
PrintResults(r.Results) PrintResults(r.Results)
return ExitSuccess, nil return ExitSuccess, nil

View File

@ -65,7 +65,7 @@ func SetColorCmd(args CmdArgs) (int, error) {
if (hueFlag == "" || saturationFlag == "") && rgbFlag == "" && name == "" { if (hueFlag == "" || saturationFlag == "") && rgbFlag == "" && name == "" {
printCmdHelp(os.Args[1]) printCmdHelp(os.Args[1])
return ExitError, nil return ExitFailure, nil
} }
if hueFlag != "" || saturationFlag != "" { if hueFlag != "" || saturationFlag != "" {
@ -85,17 +85,17 @@ func SetColorCmd(args CmdArgs) (int, error) {
} else if rgbFlag != "" { } else if rgbFlag != "" {
color, err := parseRGB(rgbFlag) color, err := parseRGB(rgbFlag)
if err != nil { if err != nil {
return ExitError, err return ExitFailure, err
} }
state.Color = color state.Color = color
} else if name != "" { } else if name != "" {
hsb, ok := args.Config.Colors[name] hsb, ok := args.Config.Colors[name]
if !ok { if !ok {
return ExitError, fmt.Errorf("%s is not a defined color", name) return ExitFailure, fmt.Errorf("%s is not a defined color", name)
} }
color, err := lifx.NewHSBColor(hsb[0], hsb[1], hsb[2]) color, err := lifx.NewHSBColor(hsb[0], hsb[1], hsb[2])
if err != nil { if err != nil {
return ExitError, err return ExitFailure, err
} }
state.Color = color state.Color = color
} }
@ -115,7 +115,7 @@ func SetColorCmd(args CmdArgs) (int, error) {
r, err := c.SetState(selector, state) r, err := c.SetState(selector, state)
if err != nil { if err != nil {
fmt.Printf("fatal: %s\n", err) fmt.Printf("fatal: %s\n", err)
return ExitError, err return ExitFailure, err
} }
if !fast { if !fast {

View File

@ -75,7 +75,7 @@ func SetStateCmd(args CmdArgs) (int, error) {
r, err := c.SetState(selector, state) r, err := c.SetState(selector, state)
if err != nil { if err != nil {
return ExitError, err return ExitFailure, err
} }
if !fast { if !fast {

View File

@ -58,7 +58,7 @@ func SetWhiteCmd(args CmdArgs) (int, error) {
kelvin := args.Flags.Int16("kelvin") kelvin := args.Flags.Int16("kelvin")
color, err := lifx.NewWhite(kelvin) color, err := lifx.NewWhite(kelvin)
if err != nil { if err != nil {
return ExitError, err return ExitFailure, err
} }
state.Color = color state.Color = color
} }
@ -68,7 +68,7 @@ func SetWhiteCmd(args CmdArgs) (int, error) {
name := args.Flags.String("name") name := args.Flags.String("name")
color, err := lifx.NewWhiteString(name) color, err := lifx.NewWhiteString(name)
if err != nil { if err != nil {
return ExitError, err return ExitFailure, err
} }
state.Color = color state.Color = color
} }
@ -93,7 +93,7 @@ func SetWhiteCmd(args CmdArgs) (int, error) {
r, err := c.SetState(selector, state) r, err := c.SetState(selector, state)
if err != nil { if err != nil {
return ExitError, err return ExitFailure, err
} }
if !fast { if !fast {

View File

@ -29,7 +29,7 @@ func ToggleCmd(args CmdArgs) (int, error) {
selector := args.Flags.String("selector") selector := args.Flags.String("selector")
r, err := c.Toggle(selector, duration) r, err := c.Toggle(selector, duration)
if err != nil { if err != nil {
return ExitError, err return ExitFailure, err
} }
PrintResults(r.Results) PrintResults(r.Results)
return ExitSuccess, nil return ExitSuccess, nil