-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
132 lines (110 loc) · 2.1 KB
/
main.go
File metadata and controls
132 lines (110 loc) · 2.1 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package main
import (
"dev/cqb13/gstats/commands"
"dev/cqb13/gstats/utils"
"fmt"
"os"
"strings"
)
type Command int
const (
Downloads Command = iota
Help
Followers
Following
Repo
Starred
User
)
func main() {
args := os.Args[1:]
if len(args) == 0 {
commands.Help()
return
}
flags := utils.NewFlagSet()
flags.AddBoolFlag("verbose", false)
flags.Parse(args)
posArgs := flags.PosArgs()
command := matchCommand(posArgs[0])
verbose := flags.GetBool("verbose")
switch command {
case Downloads:
if len(args) < 3 {
fmt.Println("Not enough args: downloads [user] [repo]")
return
}
user := posArgs[1]
repo := posArgs[2]
commands.HandleDownloadsCommand(user, repo, verbose)
return
case Help:
commands.Help()
return
case Followers:
if len(args) < 2 {
fmt.Println("Not enough args: followers [user]")
return
}
user := posArgs[1]
commands.HandleRelationsCommand(user, commands.Followers, verbose)
return
case Following:
if len(args) < 2 {
fmt.Println("Not enough args: following [user]")
return
}
user := posArgs[1]
commands.HandleRelationsCommand(user, commands.Following, verbose)
return
case Repo:
if len(args) < 3 {
fmt.Println("Not enough args: repo [user] [repo]")
return
}
user := posArgs[1]
repo := posArgs[2]
commands.HandleRepoCommand(user, repo, verbose)
return
case Starred:
if len(args) < 2 {
fmt.Println("Not enough args: user [user]")
return
}
user := posArgs[1]
commands.HandleStarredCommand(user, verbose)
return
case User:
if len(args) < 2 {
fmt.Println("Not enough args: user [user]")
return
}
user := posArgs[1]
commands.HandleUserCommand(user, verbose)
return
default:
fmt.Printf("%s is not a valid command\n", args[0])
commands.Help()
return
}
}
func matchCommand(cmd string) Command {
switch strings.ToLower(cmd) {
case "downloads":
return Downloads
case "help":
return Help
case "followers":
return Followers
case "following":
return Following
case "repo":
return Repo
case "starred":
return Starred
case "user":
return User
default:
return Help
}
}