-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
61 lines (51 loc) · 1.31 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
package main
import (
"flag"
"fmt"
"os"
"github.com/ReddyKousic/skycli/cmd"
)
func main() {
if len(os.Args) < 2 {
fmt.Println("Usage: skycli <command> [arguments]")
fmt.Println("Commands:")
fmt.Println(" setapi Set the API key")
fmt.Println(" setloc Set the locality")
os.Exit(1)
}
switch os.Args[1] {
case "setapi":
setAPICmd := flag.NewFlagSet("setapi", flag.ExitOnError)
apiKey := setAPICmd.String("key", "", "WeatherAPI API key")
setAPICmd.Parse(os.Args[2:])
if *apiKey == "" {
fmt.Println("Please provide an API key using the -key flag")
setAPICmd.PrintDefaults()
os.Exit(1)
}
err := cmd.SaveAPIKey(*apiKey)
if err != nil {
fmt.Printf("Error saving API key: %v\n", err)
os.Exit(1)
}
fmt.Println("API key saved successfully")
case "setloc":
setLocCmd := flag.NewFlagSet("setloc", flag.ExitOnError)
locality := setLocCmd.String("loc", "", "Locality")
setLocCmd.Parse(os.Args[2:])
if *locality == "" {
fmt.Println("Please provide a locality using the -loc flag")
setLocCmd.PrintDefaults()
os.Exit(1)
}
err := cmd.SaveLocality(*locality)
if err != nil {
fmt.Printf("Error saving locality: %v\n", err)
os.Exit(1)
}
fmt.Println("Locality saved successfully")
default:
fmt.Printf("%q is not a valid command.\n", os.Args[1])
os.Exit(2)
}
}