Skip to content

Commit

Permalink
Add additional checks on args
Browse files Browse the repository at this point in the history
Signed-off-by: Richard Gee <[email protected]>
  • Loading branch information
rgee0 committed Dec 3, 2023
1 parent 3b86893 commit 006e1a0
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,19 @@ func setParticle(p *string) rune {
return rune(0)
}

func getMode(m []string) (string, error) {

var retMode string

if len(m[1:]) > 0 {
retMode = strings.ToLower(m[1])
if retMode == "tree" || retMode == "snow" {
return retMode, nil
}
}
return "", fmt.Errorf("supported commands are 'snow' and 'tree'")
}

func main() {

snowCmd := flag.NewFlagSet("snow", flag.ExitOnError)
Expand All @@ -185,9 +198,9 @@ func main() {
os.Exit(0)
}()

mode := strings.ToLower(os.Args[1])
if mode != "tree" && mode != "snow" {
fmt.Println("supported commands are 'snow' and 'tree'")
mode, err := getMode(os.Args)
if err != nil {
fmt.Printf("%s", err)
os.Exit(1)
}

Expand Down

0 comments on commit 006e1a0

Please sign in to comment.