pokecli/internal/commands/visit.go
Dan Anglin bec43a3bbc
fix(BREAKING): update project name
Update project's name from pokedex to pokecli.
2024-09-22 13:17:47 +01:00

40 lines
847 B
Go

package commands
import (
"errors"
"fmt"
"codeflow.dananglin.me.uk/apollo/pokecli/internal/pokeclient"
"codeflow.dananglin.me.uk/apollo/pokecli/internal/poketrainer"
)
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
}
}