Skip to content

Commit

Permalink
Merge pull request #18 from tmck-code/handle-bad-name-input
Browse files Browse the repository at this point in the history
Log an error if a name token has no matches
  • Loading branch information
tmck-code authored Mar 22, 2022
2 parents 3f8c003 + e36eb6a commit 656f367
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pokesay.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,12 @@ func main() {
}

if args.NameToken != "" {
matches := collectPokemonWithToken(pokemon, args.NameToken)
if len(matches) == 0 {
log.Fatal(fmt.Sprintf("Not a valid name: '%s'", args.NameToken))
}
printSpeechBubble(bufio.NewScanner(os.Stdin), args)
printPokemon(chooseRandomPokemon(collectPokemonWithToken(pokemon, args.NameToken)))
printPokemon(chooseRandomPokemon(matches))
os.Exit(0)
}

Expand Down

0 comments on commit 656f367

Please sign in to comment.