diff options
author | Alex Crawford <wally@code.acrawford.com> | 2021-04-07 15:19:00 -0700 |
---|---|---|
committer | Alex Crawford <wally@code.acrawford.com> | 2021-04-07 16:05:00 -0700 |
commit | f82dc4c66c2b2342f52b99651e75ecda4a2c39bb (patch) | |
tree | 6870113f33465e5050604f5cf33ff0b5a8ac5528 | |
parent | 5fc17632dc04335107cdac51230cdd5e2aa05ea0 (diff) |
main: use unique exitcode for incorrect invocation
Command line utilities typically exit with a specific exitcode to
indicate incorrect invocation. Golang has settled on 2, so let's go with
that.
This also moves the file extension check before the check for the
firmware's existence. No point in validating that the file exists if we
already know it has the wrong extension.
-rw-r--r-- | main.go | 12 |
1 files changed, 6 insertions, 6 deletions
@@ -24,7 +24,7 @@ func main() { if len(args) != 1 { fmt.Println(aurora.Blue("Usage: wally-cli <firmware file>")) - os.Exit(0) + os.Exit(2) } if args[0] == "--version" { @@ -34,14 +34,14 @@ func main() { } path := args[0] - if _, err := os.Stat(path); os.IsNotExist(err) { - fmt.Println(aurora.Red("The file path you specified does not exist")) - os.Exit(1) - } - extension := filepath.Ext(path) if extension != ".bin" && extension != ".hex" { fmt.Println(aurora.Red("Please provide a valid firmware file: a"), aurora.Red(aurora.Underline(".hex")), aurora.Red("file (ErgoDox EZ) or a"), aurora.Red(aurora.Underline(".bin")), aurora.Red("file (Moonlander / Planck EZ)")) + os.Exit(2) + } + + if _, err := os.Stat(path); os.IsNotExist(err) { + fmt.Println(aurora.Red("The file path you specified does not exist")) os.Exit(1) } |