Skip to content

Commit

Permalink
Add quiet output
Browse files Browse the repository at this point in the history
  • Loading branch information
moncho committed Mar 5, 2017
1 parent 4ae0865 commit e99b198
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
5 changes: 4 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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
}

Expand All @@ -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{}
}
Expand Down
2 changes: 1 addition & 1 deletion output/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions output/quiet.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit e99b198

Please sign in to comment.