generated from templates/go-generic
checkpoint: add pokedex command
This commit is contained in:
parent
c413e3149e
commit
9d7ee5fede
1 changed files with 24 additions and 1 deletions
25
main.go
25
main.go
|
@ -80,6 +80,11 @@ func run() {
|
|||
description: "Inspects a Pokemon from your Pokedex",
|
||||
callback: inspectFunc(),
|
||||
},
|
||||
"pokedex": {
|
||||
name: "pokedex",
|
||||
description: "Lists the names of all the Pokemon in your Pokedex",
|
||||
callback: pokedexFunc(),
|
||||
},
|
||||
}
|
||||
|
||||
summaries := summaryMap(commandMap)
|
||||
|
@ -241,7 +246,7 @@ func catchFunc(client *pokeclient.Client) callbackFunc {
|
|||
|
||||
if caught := catchPokemon(chance); caught {
|
||||
dexter[pokemonName] = pokemon
|
||||
fmt.Printf("%s was caught!\n", pokemonName)
|
||||
fmt.Printf("%s was caught!\nYou may now inspect it with the inspect command.\n", pokemonName)
|
||||
} else {
|
||||
fmt.Printf("%s escaped!\n", pokemonName)
|
||||
}
|
||||
|
@ -297,6 +302,24 @@ func inspectFunc() callbackFunc {
|
|||
}
|
||||
}
|
||||
|
||||
func pokedexFunc() callbackFunc {
|
||||
return func(_ []string) error {
|
||||
if len(dexter) == 0 {
|
||||
fmt.Println("You have no Pokemon in your Pokedex")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
fmt.Println("Your Pokedex:")
|
||||
|
||||
for name := range maps.All(dexter) {
|
||||
fmt.Println(" -", name)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func printResourceList(client *pokeclient.Client, url string, state *State) error {
|
||||
list, err := client.GetNamedAPIResourceList(url)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in a new issue