2024-09-21 16:53:11 +01:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
|
2024-09-22 13:17:47 +01:00
|
|
|
"codeflow.dananglin.me.uk/apollo/pokecli/internal/pokeclient"
|
|
|
|
"codeflow.dananglin.me.uk/apollo/pokecli/internal/poketrainer"
|
2024-09-21 16:53:11 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func VisitFunc(client *pokeclient.Client, trainer *poketrainer.Trainer) CommandFunc {
|
|
|
|
return func(args []string) error {
|
|
|
|
if args == nil {
|
|
|
|
return errors.New("the location area has not been specified")
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(args) != 1 {
|
|
|
|
return fmt.Errorf(
|
|
|
|
"unexpected number of location areas: want 1; got %d",
|
|
|
|
len(args),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
locationAreaName := args[0]
|
|
|
|
|
|
|
|
locationArea, err := client.GetLocationArea(locationAreaName)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf(
|
|
|
|
"unable to get the location area: %w",
|
|
|
|
err,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
trainer.UpdateCurrentLocationAreaName(locationArea.Name)
|
|
|
|
|
|
|
|
fmt.Println("You are now visiting", locationArea.Name)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|