Fixed handling of blank inputs.

Now properly removes ~/.venture when input is blank, and returns succesfully if
the file came already pre-non-existing.
main
diff 2020-11-13 04:16:43 +00:00
parent 615246bdc7
commit 4f501c5d65
1 changed files with 7 additions and 4 deletions

11
main.go
View File

@ -9,6 +9,7 @@ import (
"io" "io"
"io/ioutil" "io/ioutil"
"bufio" "bufio"
"strings"
) )
func main() { func main() {
@ -18,8 +19,7 @@ func main() {
err := SetVenture(flag.Args()[1:]) err := SetVenture(flag.Args()[1:])
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "Could not set: %v", err) fmt.Fprintf(os.Stderr, "Could not set: %v", err)
} }
default: default:
fmt.Printf("Usage:\n\t%v set\n", os.Args[0]) fmt.Printf("Usage:\n\t%v set\n", os.Args[0])
flag.PrintDefaults() flag.PrintDefaults()
@ -45,9 +45,12 @@ func SetVenture(args []string) error {
} }
// Remove file on blank input // Remove file on blank input
if len(input) < 1 { if strings.TrimSpace(input) == "" {
err = os.Remove(outputPath) err = os.Remove(outputPath)
if err != nil { // File already pre-non-existing is considered success.
if os.IsNotExist(err) {
return nil
} else if err != nil {
return err return err
} }
return nil return nil