-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
53 lines (45 loc) · 1.1 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
package main
import (
"flag"
"fmt"
"os"
"strings"
"github.com/moncho/gh-download-count/github"
"github.com/moncho/gh-download-count/output"
)
var quiet = flag.Bool("quiet", false, "shows just the download count")
var detail = flag.Bool("detail", false, "shows download count per release")
var json = flag.Bool("json", false, "generates a json with the download count")
func main() {
flag.Parse()
args := flag.Args()
if len(args) == 0 || len(args) > 2 {
fmt.Printf("Got %d args, was expecting \"owner/repo\".\n", len(args))
return
}
owner, repo := parseArgs(args)
p, err := github.NewProject(owner, repo)
if err != nil {
fmt.Println(err.Error())
return
}
var w output.ProjectWriter
if *detail {
w = output.ASCIITableWriter{}
} else if *json {
w = output.JSONWriter{}
} else if *quiet {
w = output.QuietWriter{}
} else {
w = output.DefaultProjectWriter{}
}
w.Write(os.Stdout, p)
}
func parseArgs(args []string) (string, string) {
argsCount := len(args)
if argsCount == 1 {
sep := strings.Index(args[0], "/")
return args[0][0:sep], args[0][sep+1:]
}
return args[0], args[1]
}