From 4ae086544f76c8540d0be726326ef06fc760e35f Mon Sep 17 00:00:00 2001 From: moncho Date: Sun, 5 Mar 2017 19:37:20 +0100 Subject: [PATCH] Create main --- main.go | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 main.go diff --git a/main.go b/main.go new file mode 100644 index 0000000..fa45070 --- /dev/null +++ b/main.go @@ -0,0 +1,50 @@ +package main + +import ( + "flag" + "fmt" + "os" + "strings" + + "github.com/moncho/gh-download-count/github" + "github.com/moncho/gh-download-count/output" +) + +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 1 or 2.", 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 { + 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] +}