-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepl.go
42 lines (38 loc) · 848 Bytes
/
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
package main
import (
"bufio"
"fmt"
"os"
"time"
pokecache "github.com/chichigami/pokedex/internal"
)
func repl() {
fmt.Println("Welcome to the Pokedex!")
var config = Config{
cache: pokecache.NewCache(10 * time.Minute),
caughtPokemons: map[string]Pokemon{},
}
for {
var input string
scanner := bufio.NewScanner(os.Stdin)
fmt.Print("Pokedex > ")
if scanner.Scan() {
input = scanner.Text()
}
splitted_input := cleanInput(input)
command := splitted_input[0]
if _, ok := getCommands()[command]; !ok {
fmt.Println("Unknown command")
} else {
var err error
if len(splitted_input) > 1 {
err = getCommands()[splitted_input[0]].callback(&config, splitted_input[1])
} else {
err = getCommands()[splitted_input[0]].callback(&config)
}
if err != nil {
fmt.Println(err)
}
}
}
}