diff --git a/main.go b/main.go index fa45070..90b21b2 100644 --- a/main.go +++ b/main.go @@ -10,6 +10,7 @@ import ( "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") @@ -18,7 +19,7 @@ func main() { args := flag.Args() if len(args) == 0 || len(args) > 2 { - fmt.Printf("Got %d args, was expecting 1 or 2.", len(args)) + fmt.Printf("Got %d args, was expecting \"owner/repo\".\n", len(args)) return } @@ -34,6 +35,8 @@ func main() { w = output.ASCIITableWriter{} } else if *json { w = output.JSONWriter{} + } else if *quiet { + w = output.QuietWriter{} } else { w = output.DefaultProjectWriter{} } diff --git a/output/default.go b/output/default.go index c34acf5..e2472b8 100644 --- a/output/default.go +++ b/output/default.go @@ -11,7 +11,7 @@ import ( type DefaultProjectWriter struct { } -//Write writes the total download count on the given writer.s +//Write writes the project name and the total download count on the given writer. func (w DefaultProjectWriter) Write(out io.Writer, p *api.Project) error { _, err := fmt.Fprintf(out, "Project %s has been downloaded %d times.\n", p.Name, p.DownloadCount()) return err diff --git a/output/quiet.go b/output/quiet.go new file mode 100644 index 0000000..bcd7069 --- /dev/null +++ b/output/quiet.go @@ -0,0 +1,18 @@ +package output + +import ( + "fmt" + "io" + + "github.com/moncho/gh-download-count/api" +) + +//QuietWriter just writes the download count. +type QuietWriter struct { +} + +//Write writes the total download count on the given writer. +func (w QuietWriter) Write(out io.Writer, p *api.Project) error { + _, err := fmt.Fprintf(out, "%d\n", p.DownloadCount()) + return err +}