From 9d7ee5fede45506d5c85c4076b04314fd2f38534 Mon Sep 17 00:00:00 2001 From: Dan Anglin Date: Fri, 20 Sep 2024 10:48:43 +0100 Subject: [PATCH] checkpoint: add pokedex command --- main.go | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index e3aeeb7..b44954e 100644 --- a/main.go +++ b/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 {