Skip to content

Commit

Permalink
Change verbose option to show-details
Browse files Browse the repository at this point in the history
  • Loading branch information
umutphp committed May 23, 2020
1 parent 560595c commit c5b186c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
18 changes: 9 additions & 9 deletions lib/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type CLI struct {
username string
token string
day int
verbose int
showDetails int
client *github.Client
context context.Context
accountTotalChannel chan int
Expand All @@ -29,7 +29,7 @@ func New(token string) CLI {
username: "",
token: "",
day: 0,
verbose: 1,
showDetails: 1,
}

cli.SetToken(token)
Expand Down Expand Up @@ -58,14 +58,14 @@ func (cli *CLI) SetDay(day int) {
cli.day = day
}

func (cli *CLI) SetVerbose(verbose int) {
cli.verbose = verbose
func (cli *CLI) ShowDetails(showDetails int) {
cli.showDetails = showDetails
}

func (cli *CLI) Initialize() bool {
user, _, err := cli.client.Users.Get(cli.context, "")
if err != nil {
fmt.Println("GitHub API authentication failed. Token may be invalid.")
fmt.Println("GitHub API authentication failed. Token may be invalid.", cli.token)
return false
}

Expand All @@ -92,7 +92,7 @@ func (cli *CLI) GetRepos() []*github.Repository {

func (cli *CLI) RepoStat(w io.Writer) {
for repo := range cli.repoChannel {
if cli.verbose == 1 {
if cli.showDetails == 1 {
fmt.Print(".")
}

Expand All @@ -109,7 +109,7 @@ func (cli *CLI) RepoStat(w io.Writer) {
}
}

if cli.verbose == 1 {
if cli.showDetails == 1 {
fmt.Fprintf(w, "%s\t%d\t%d\t\n", repo.GetFullName(), viewCount, uniqueCount)
}

Expand All @@ -122,14 +122,14 @@ func (cli *CLI) RepoStat(w io.Writer) {

func (cli *CLI) Execute(w io.Writer) {
fmt.Print("Checking repositories ")

repos := cli.GetRepos()
repoCount := len(repos)

cli.accountTotalChannel = make(chan int, repoCount)
cli.accountUniqueChannel = make(chan int, repoCount)

if cli.verbose == 1 {
if cli.showDetails == 1 {
fmt.Fprintf(w, "Repository\tTotal View\tUnique View\t\n")
}

Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ func main() {

CLI.SetDay(c.Int("day"))

if c.Int("verbose") == 0 {
CLI.SetVerbose(c.Int("verbose"))
if c.Int("show-details") == 0 {
CLI.ShowDetails(c.Int("show-details"))
}

if CLI.Initialize() == true {
Expand Down

0 comments on commit c5b186c

Please sign in to comment.