generated from templates/go-generic
checkpoint: add inspect command
This commit is contained in:
parent
ccb341fef4
commit
c413e3149e
1 changed files with 56 additions and 4 deletions
60
main.go
60
main.go
|
@ -67,14 +67,19 @@ func run() {
|
||||||
},
|
},
|
||||||
"explore": {
|
"explore": {
|
||||||
name: "explore",
|
name: "explore",
|
||||||
description: "Lists all the pokemon in a given area",
|
description: "Lists all the Pokemon in a given area",
|
||||||
callback: exploreFunc(client),
|
callback: exploreFunc(client),
|
||||||
},
|
},
|
||||||
"catch": {
|
"catch": {
|
||||||
name: "catch",
|
name: "catch",
|
||||||
description: "Catches a pokemon and adds them to your Pokedex",
|
description: "Catches a Pokemon and adds them to your Pokedex",
|
||||||
callback: catchFunc(client),
|
callback: catchFunc(client),
|
||||||
},
|
},
|
||||||
|
"inspect": {
|
||||||
|
name: "inspect",
|
||||||
|
description: "Inspects a Pokemon from your Pokedex",
|
||||||
|
callback: inspectFunc(),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
summaries := summaryMap(commandMap)
|
summaries := summaryMap(commandMap)
|
||||||
|
@ -245,6 +250,53 @@ func catchFunc(client *pokeclient.Client) callbackFunc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func inspectFunc() callbackFunc {
|
||||||
|
return func(args []string) error {
|
||||||
|
if args == nil {
|
||||||
|
return errors.New("the name of the Pokemon has not been specified")
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(args) != 1 {
|
||||||
|
return fmt.Errorf(
|
||||||
|
"unexpected number of Pokemon names: want 1; got %d",
|
||||||
|
len(args),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
pokemonName := args[0]
|
||||||
|
|
||||||
|
pokemon, ok := dexter[pokemonName]
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("you have not caught %s", pokemonName)
|
||||||
|
}
|
||||||
|
|
||||||
|
info := fmt.Sprintf(
|
||||||
|
"Name: %s\nHeight: %d\nWeight: %d\nStats:",
|
||||||
|
pokemon.Name,
|
||||||
|
pokemon.Height,
|
||||||
|
pokemon.Weight,
|
||||||
|
)
|
||||||
|
|
||||||
|
for _, stat := range slices.All(pokemon.Stats) {
|
||||||
|
info += fmt.Sprintf(
|
||||||
|
"\n - %s: %d",
|
||||||
|
stat.Stat.Name,
|
||||||
|
stat.BaseStat,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
info += "\nTypes:"
|
||||||
|
|
||||||
|
for _, pType := range slices.All(pokemon.Types) {
|
||||||
|
info += "\n - " + pType.Type.Name
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println(info)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func printResourceList(client *pokeclient.Client, url string, state *State) error {
|
func printResourceList(client *pokeclient.Client, url string, state *State) error {
|
||||||
list, err := client.GetNamedAPIResourceList(url)
|
list, err := client.GetNamedAPIResourceList(url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -286,11 +338,11 @@ func parseArgs(input string) (string, []string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func catchPokemon(chance int) bool {
|
func catchPokemon(chance int) bool {
|
||||||
if chance == 100 {
|
if chance >= 100 {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
if chance == 0 {
|
if chance <= 0 {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue