-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
83 lines (72 loc) · 1.89 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package main
import (
"fmt"
"time"
"github.com/granadosbrand/poke-cli/internal/pokeapi"
"github.com/granadosbrand/poke-cli/internal/pokecache"
)
type cliCommand struct {
name string
description string
callback func(*config, ...string) error
}
type config struct {
pokeapiClient pokeapi.Client
nextLocationAreaURL *string
previousLocationAreaURL *string
pokeCache pokecache.Cache
caugthPokemons map[string]pokeapi.Pokemon
}
func commands() map[string]cliCommand {
return map[string]cliCommand{
"help": {
name: "help",
description: " Displays a help message",
callback: commandHelp,
},
"exit": {
name: "exit",
description: " Exit poke-cli",
callback: exitCommand,
},
"map": {
name: "map",
description: " Displays the names of 20 location areas in the Pokémon world.",
callback: mapCommand,
},
"mapb": {
name: "mapb",
description: " Displays the previous 20 location areas in the Pokémon world.",
callback: mapbCommand,
},
"explore": {
name: "explore <area>",
description: " Display a list of pokemon in a given area",
callback: explore,
},
"catch": {
name: "catch <pokemon_name>",
description: " Catch a Pokémon",
callback: catch,
},
"inspect": {
name: "inspect <pokemon_name>",
description: " Lets you see the details of the Pokémons you have already caught.",
callback: inspectCallback,
},
"pokedex": {
name: "pokedex",
description: " List of the Pokémons you have already caught.",
callback: pokedexCallback,
},
}
}
func main() {
cfg := config{
pokeapiClient: pokeapi.NewClient(5 * time.Minute),
caugthPokemons: map[string]pokeapi.Pokemon{},
}
fmt.Println("¡Welcome to Poke-Cli!")
fmt.Println("Type help to see available commands")
newConsole(&cfg)
}