-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommands_map.go
62 lines (51 loc) · 1.34 KB
/
commands_map.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
package main
import "fmt"
func commandMap(cfg *config, args ...string) error {
if cfg.NextUrl == nil && cfg.PreviousUrl != nil {
return fmt.Errorf("you are already at the end of the location list")
}
data, err := cfg.ApiClient.FetchLocations(cfg.NextUrl)
if err != nil {
return err
}
cfg.NextUrl = data.Next
cfg.PreviousUrl = data.Previous
for _, location := range data.Locations {
fmt.Printf("%s\n", location.Name)
}
return nil
}
func commandMapB(cfg *config, args ...string) error {
if cfg.PreviousUrl == nil {
return fmt.Errorf("you are already at the start of the location list")
}
data, err := cfg.ApiClient.FetchLocations(cfg.PreviousUrl)
if err != nil {
return err
}
cfg.NextUrl = data.Next
cfg.PreviousUrl = data.Previous
for _, location := range data.Locations {
fmt.Printf("%s\n", location.Name)
}
return nil
}
func commandExplore(cfg *config, args ...string) error {
if len(args) == 0 {
return fmt.Errorf("you haven't provided a location to explore!")
}
area := args[0]
fmt.Printf("Exploring %s...\n", area)
data, err := cfg.ApiClient.ExploreLocation(area)
if err != nil {
return err
}
if len(data.Encounters) == 0 {
return fmt.Errorf("no pokemon found!")
}
fmt.Println("Found Pokemon:")
for _, encounter := range data.Encounters {
fmt.Printf(" - %v\n", encounter.Pokemon.Name)
}
return nil
}