Skip to content

Commit

Permalink
Merge pull request #2 from gennaro-tedesco/stats
Browse files Browse the repository at this point in the history
Stats
  • Loading branch information
gennaro-tedesco authored Mar 18, 2021
2 parents 1dc6f51 + fe2f255 commit 75bd6aa
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 60 deletions.
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<a href="#Feedback">Feedback</a>
</p>

Retrieve GitHub statistics per username easily from the command line: no need to open the browser anymore!
Retrieve GitHub statistics per username from the command line: no need to open the browser anymore!

![](img/demo.gif)

Expand All @@ -26,11 +26,10 @@ go get -u -v github.com/gennaro-tedesco/stargazer
## Usage
`stargazer` requires a mandatory argument as GitHub username and exposes the following commands:

| command | example usage | flags
|:------- |:----------------------------- |:----------------
| stars | stargazer stars neovim | --sort
| forks | stargazer forks tpope | --sort
| url | stargazer url gennaro-tedesco |
| command | example usage | flags | description
|:------- |:----------------------------- |:------ |:------------
| stats | stargazer stats neovim | --sort | list stars and forks per repository
| url | stargazer url gennaro-tedesco | | list repositories url and main language

the general grammar being `stargazer <cmd> username --flag`. See `stargazer help` for details.

Expand Down
33 changes: 8 additions & 25 deletions cmd/getters.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,43 +10,26 @@ import (
)

type RepoJson struct {
Name string `json:"name"`
Stars int `json:"stargazers_count"`
Forks int `json:"forks"`
HtmlUrl string `json:"html_url"`
Name string `json:"name"`
Stars int `json:"stargazers_count"`
Forks int `json:"forks"`
HtmlUrl string `json:"html_url"`
Language string `json:"language"`
}

func getStars(repos []RepoJson, sort bool) {
func getStats(repos []RepoJson, sort bool) {
t := table.NewWriter()
t.SetOutputMirror(os.Stdout)
t.AppendHeader(table.Row{"name", "stars"})
t.AppendHeader(table.Row{"name", "stars", "forks"})
for _, repo := range repos {
t.AppendRows([]table.Row{
{repo.Name, repo.Stars},
{repo.Name, repo.Stars, repo.Forks},
})
}
t.AppendSeparator()
t.SetStyle(table.StyleLight)
if sort {
t.SortBy([]table.SortBy{{Name: "stars", Mode: table.DscNumeric}})
}
t.Render()
}

func getForks(repos []RepoJson, sort bool) {
t := table.NewWriter()
t.SetOutputMirror(os.Stdout)
t.AppendHeader(table.Row{"name", "forks"})
for _, repo := range repos {
t.AppendRows([]table.Row{
{repo.Name, repo.Forks},
})
}
t.AppendSeparator()
t.SetStyle(table.StyleLight)
if sort {
t.SortBy([]table.SortBy{{Name: "forks", Mode: table.DscNumeric}})
t.SortBy([]table.SortBy{{Name: "stars", Mode: table.DscNumeric}, {Name: "forks", Mode: table.DscNumeric}})
}
t.Render()
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
var rootCmd = &cobra.Command{
Use: "stargazer",
Args: cobra.ExactArgs(1),
Short: "stargazer: CLI to fetch GitHub repositories statistics",
Long: "stargazer: CLI to fetch GitHub repositories statistics",
Short: "stargazer: retrieve github statistics",
Long: "stargazer: CLI to retrieve statistics of users' github repositories",
Run: func(cmd *cobra.Command, args []string) {
var repos = getRepoList(args[0])
getUrl(repos)
Expand Down
21 changes: 0 additions & 21 deletions cmd/stars.go

This file was deleted.

12 changes: 6 additions & 6 deletions cmd/forks.go → cmd/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ import (
"github.com/spf13/cobra"
)

var forksCmd = &cobra.Command{
Use: "forks",
var statsCmd = &cobra.Command{
Use: "stats",
Args: cobra.ExactArgs(1),
Short: "forks count per repository",
Long: "list user's GitHub repositories with corresponding forks count",
Short: "stats counts per repository",
Long: "list user's github repositories showing number of stars and forks",
Run: func(cmd *cobra.Command, args []string) {
repos := getRepoList(args[0])
sort, _ := cmd.Flags().GetBool("sort")
getForks(repos, sort)
getStats(repos, sort)
},
}

func init() {
rootCmd.AddCommand(forksCmd)
rootCmd.AddCommand(statsCmd)
}
Binary file modified img/demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 75bd6aa

Please sign in to comment.