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
parent
615246bdc7
commit
4f501c5d65
9
main.go
9
main.go
|
@ -9,6 +9,7 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -19,7 +20,6 @@ func main() {
|
||||||
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
|
||||||
|
|
Loading…
Reference in New Issue