-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepl.go
84 lines (71 loc) · 1.84 KB
/
repl.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
84
package main
import (
"bufio"
"fmt"
"os"
"strings"
"github.com/almaraz333/go-pokedex-cli/internal"
)
func startRepl() {
config := internal.Config{NextUrl: "https://pokeapi.co/api/v2/location-area"}
cache := internal.NewCache(10000)
commands := map[string]internal.CliCommand{
"help": {
Name: "help",
Description: "Displays a help message",
Callback: internal.HelpCallback,
},
"exit": {
Name: "exit",
Description: "Exit the Pokedex",
Callback: internal.ExitCallback,
},
"map": {
Name: "map",
Description: "displays the names of 20 location areas in the Pokemon world",
Callback: internal.MapCallback,
},
"mapb": {
Name: "mapb",
Description: "displays the previous 20 locations",
Callback: internal.MapBackCallback,
},
"explore": {
Name: "Explore",
Description: "Explore the current area",
Callback: internal.ExploreCallbak,
},
"catch": {
Name: "Catch",
Description: "Catch a pokemon in the current area",
Callback: internal.CatchCallback,
},
"inspect": {
Name: "Inspect",
Description: "Get info about a pokemon in your pokedex",
Callback: internal.InspectCallback,
},
"pokedex": {
Name: "Pokedex",
Description: "List the pokemon in your pokedex",
Callback: internal.PokedexCallback,
},
}
scanner := bufio.NewScanner(os.Stdin)
params := &internal.PokeParams{}
pokedex := map[string]internal.PokemonRes{}
for {
fmt.Print("\nPokedex > ")
scanner.Scan()
commandSplit := strings.Split(scanner.Text(), " ")
command := commandSplit[0]
if command == "explore" {
params.Location = commandSplit[1]
} else if command == "catch" {
params.PokemonToCatch = commandSplit[1]
}
if val, ok := commands[command]; ok {
val.Callback(&config, &cache, params, pokedex)
}
}
}