-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathghlog.go
More file actions
92 lines (72 loc) · 1.7 KB
/
ghlog.go
File metadata and controls
92 lines (72 loc) · 1.7 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
package main
import (
"errors"
"fmt"
"log"
"os"
"strconv"
"main.com/auth"
"main.com/github"
)
const GHLOG_VERSION string = "v0.1.0"
const HELP_STRING string = `
usage: ghlog <command>
Here are few commands:
repo Print all repositories on your github
org Print all organizations you joined
create repo Create a new repository
heatmap [user] Print all contributions as heatmap calendar
You can also search repositories using:
search <query> [from] [to] Search repositories from [from] to [to]
Default value
[from] = 0
[to] = 5`
func run(args []string) {
if len(args) == 0 {
args = append(args, "help")
}
if args[0] == "help" {
printHelp()
return
}
accessToken, id := auth.GetAuth()
client, ctx := github.GithubClient(accessToken)
switch args[0] {
case "repo":
github.PrintRepositories(client, ctx)
case "org":
github.PrintOrganizations(client, ctx)
case "create":
if len(args) < 2 {
log.Fatalln(errors.New("Can't find command."))
}
if args[1] == "repo" {
github.CreateRepository(client, ctx)
}
case "heatmap":
if len(args) < 2 {
args = append(args, id)
}
github.Heatmap(args[1])
case "search":
if len(args) < 2 {
log.Fatalln(errors.New("Missing argument."))
}
from := 0
to := 5
if len(args) >= 3 {
from, _ = strconv.Atoi(args[2])
}
if len(args) >= 4 {
to, _ = strconv.Atoi(args[3])
}
github.Search(client, ctx, args[1], from, to)
}
}
func printHelp() {
fmt.Printf("Unofficial Github Cli %s\n", GHLOG_VERSION)
fmt.Println(HELP_STRING)
}
func main() {
run(os.Args[1:])
}