-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
44 lines (36 loc) · 993 Bytes
/
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
package main
import (
"fmt"
"bufio"
"os"
"strings"
"log"
//"time"
"github.com/Enigma56/pokedex/api"
"github.com/Enigma56/pokedex/internal/pokedict"
)
func main() {
cfg := api.Config{
Pokedex: pokedict.NewPokedex(),
ApiClient: api.NewClient(),
CurrLocationAreaURL: "https://pokeapi.co/api/v2/location-area",
}
commandMap := api.CommandMap
for {
userScanner := bufio.NewScanner(os.Stdin)
fmt.Print("Pokedex > ")
userScanner.Scan()
userIn := userScanner.Text()
userIn = strings.TrimRight(userIn, "\n")
userArgs := strings.Split(userIn, " ")
cmd, ok := commandMap[userArgs[0]]
if !ok {
log.Print("Command not recognized")
}
//cmdArgs := userArgs[1:]
err := cmd(&cfg, userArgs[1:]...)
if err != nil {
fmt.Printf("Command failed with error: %v\n", err)
}
}
}