gokedex/command_map.go
2025-06-06 13:21:07 -06:00

47 lines
907 B
Go

package main
import (
"errors"
"fmt"
)
func commandMap(cfg *config, arg string) error {
// if cfg.nextLocationsURL == nil {
// return errors.New("you're on the last page")
// }
locationsResp, err := cfg.pokeClient.ListLocations(cfg.nextLocationsURL)
if err != nil {
return err
}
cfg.nextLocationsURL = locationsResp.Next
cfg.prevLocationsURL = locationsResp.Previous
for _, loc := range locationsResp.Results {
fmt.Println(" ", loc.Name)
}
return nil
}
func commandMapb(cfg *config, arg string) error {
if cfg.prevLocationsURL == nil {
return errors.New("you're on the first page")
}
locationsResp, err := cfg.pokeClient.ListLocations(cfg.prevLocationsURL)
if err != nil {
return err
}
cfg.nextLocationsURL = locationsResp.Next
cfg.prevLocationsURL = locationsResp.Previous
for _, loc := range locationsResp.Results {
fmt.Println(" ", loc.Name)
}
return nil
}