Skip to content

Commit

Permalink
move repo and org options to root command
Browse files Browse the repository at this point in the history
Lots of the commands use these options, so move them to the root for
consistent handling.

Signed-off-by: Doug Hellmann <doug@doughellmann.com>
  • Loading branch information
dhellmann committed Apr 30, 2021
1 parent 9adf95e commit a8830ef
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
5 changes: 0 additions & 5 deletions cmd/pullRequests.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,5 @@ func getName(user *github.User) string {
}

func init() {
pullRequestsCmd.Flags().StringVarP(&orgName, "org", "o", "", "github org")
pullRequestsCmd.Flags().StringVarP(&repoName, "repo", "r", "", "github repository")
pullRequestsCmd.Flags().IntVar(&daysBack, "days-back", 90,
"how many days back to query, defaults to 90")

rootCmd.AddCommand(pullRequestsCmd)
}
10 changes: 0 additions & 10 deletions cmd/reviewers.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@ const ignoreConfigOptionName = "reviewers.ignore"
// stats
var ignoredReviewers = []string{}

// orgName and repoName are the GitHub organization and repository to query
var orgName, repoName string

// daysBack is the number of days of history to examine (older items are ignored)
var daysBack int

// reviewersCmd represents the reviewers command
var reviewersCmd = &cobra.Command{
Use: "reviewers",
Expand Down Expand Up @@ -121,8 +115,4 @@ func init() {
reviewersCmd.Flags().StringSliceVarP(&ignoredReviewers,
"ignore", "i", []string{},
"ignore a reviewer (useful for bots), can be repeated")
reviewersCmd.Flags().StringVarP(&orgName, "org", "o", "", "github org")
reviewersCmd.Flags().StringVarP(&repoName, "repo", "r", "", "github repository")
reviewersCmd.Flags().IntVar(&daysBack, "days-back", 90,
"how many days back to query, defaults to 90")
}
18 changes: 16 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ var cfgFile string
// devMode is a flag telling us whether we are in developer mode
var devMode bool

// orgName and repoName are the GitHub organization and repository to query
var orgName, repoName string

// daysBack is the number of days of history to examine (older items are ignored)
var daysBack int

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "gh-review-stats",
Expand All @@ -57,8 +63,16 @@ func init() {

viper.SetDefault(githubTokenConfigOptionName, "")

rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.gh-review-stats.yml)")
rootCmd.PersistentFlags().BoolVar(&devMode, "dev", false, "enable developer mode, shortcutting some queries")
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "",
"config file (default is $HOME/.gh-review-stats.yml)")
rootCmd.PersistentFlags().BoolVar(&devMode, "dev", false,
"enable developer mode, shortcutting some queries")
rootCmd.PersistentFlags().StringVarP(&orgName, "org", "o", "",
"github org")
rootCmd.PersistentFlags().StringVarP(&repoName, "repo", "r", "",
"github repository")
rootCmd.PersistentFlags().IntVar(&daysBack, "days-back", 90,
"how many days back to query")

}

Expand Down

0 comments on commit a8830ef

Please sign in to comment.