pokecli/internal/commands/explore.go
Dan Anglin 8b03ba7be1
refactor: move command funcs to internal package
Move the command functions to the new internal commands package
2024-09-21 16:53:11 +01:00

33 lines
749 B
Go

package commands
import (
"fmt"
"slices"
"codeflow.dananglin.me.uk/apollo/pokedex/internal/pokeclient"
"codeflow.dananglin.me.uk/apollo/pokedex/internal/poketrainer"
)
func ExploreFunc(client *pokeclient.Client, trainer *poketrainer.Trainer) CommandFunc {
return func(_ []string) error {
locationAreaName := trainer.CurrentLocationAreaName()
fmt.Printf("Exploring %s...\n", locationAreaName)
locationArea, err := client.GetLocationArea(locationAreaName)
if err != nil {
return fmt.Errorf(
"unable to get the location area: %w",
err,
)
}
fmt.Println("Found Pokemon:")
for _, encounter := range slices.All(locationArea.PokemonEncounters) {
fmt.Printf("- %s\n", encounter.Pokemon.Name)
}
return nil
}
}