diff --git a/command/credits.go b/command/credits.go index e0187adb7..9d5560bad 100644 --- a/command/credits.go +++ b/command/credits.go @@ -41,19 +41,22 @@ func init() { } var creditsCmd = &cobra.Command{ - Use: "credits [repository]", - Short: "View project's credits", - Long: `View animated credits for this or another project. - -Examples: - - gh credits # see a credits animation for this project + Use: "credits", + Short: "View credits for this tool", + Long: `View animated credits for gh, the tool you are currently using :)`, + Example: `gh credits # see a credits animation for this project gh credits owner/repo # see a credits animation for owner/repo gh credits -s # display a non-animated thank you gh credits | cat # just print the contributors, one per line `, - Args: cobra.MaximumNArgs(1), - RunE: credits, + Args: cobra.ExactArgs(0), + RunE: ghCredits, + Hidden: true, +} + +func ghCredits(cmd *cobra.Command, _ []string) error { + args := []string{"cli/cli"} + return credits(cmd, args) } func credits(cmd *cobra.Command, args []string) error { @@ -64,9 +67,18 @@ func credits(cmd *cobra.Command, args []string) error { return err } - owner := "cli" - repo := "cli" - if len(args) > 0 { + var owner string + var repo string + + if len(args) == 0 { + baseRepo, err := determineBaseRepo(client, cmd, ctx) + if err != nil { + return err + } + + owner = baseRepo.RepoOwner() + repo = baseRepo.RepoName() + } else { parts := strings.SplitN(args[0], "/", 2) owner = parts[0] repo = parts[1] diff --git a/command/repo.go b/command/repo.go index f459c2310..b1a57d3a7 100644 --- a/command/repo.go +++ b/command/repo.go @@ -38,6 +38,9 @@ func init() { repoCmd.AddCommand(repoViewCmd) repoViewCmd.Flags().BoolP("web", "w", false, "Open a repository in the browser") + + repoCmd.AddCommand(repoCreditsCmd) + repoCreditsCmd.Flags().BoolP("static", "s", false, "Print a static version of the credits") } var repoCmd = &cobra.Command{ @@ -92,6 +95,19 @@ With '--web', open the repository in a web browser instead.`, RunE: repoView, } +var repoCreditsCmd = &cobra.Command{ + Use: "credits []", + Short: "View credits for a repository", + Example: `$ gh repo credits # view credits for the current repository +$ gh repo credits cool/repo # view credits for cool/repo +$ gh repo credits -s # print a non-animated thank you +$ gh repo credits | cat # pipe to just print the contributors, one per line +`, + Args: cobra.MaximumNArgs(1), + RunE: repoCredits, + Hidden: true, +} + func parseCloneArgs(extraArgs []string) (args []string, target string) { args = extraArgs @@ -597,3 +613,7 @@ func repoView(cmd *cobra.Command, args []string) error { return nil } + +func repoCredits(cmd *cobra.Command, args []string) error { + return credits(cmd, args) +} diff --git a/command/root.go b/command/root.go index 3f38dfec5..05e864eb7 100644 --- a/command/root.go +++ b/command/root.go @@ -365,7 +365,7 @@ func rootHelpFunc(command *cobra.Command, args []string) { s := " " + rpad(c.Name()+":", c.NamePadding()) + c.Short if includes(coreCommandNames, c.Name()) { coreCommands = append(coreCommands, s) - } else if c != creditsCmd { + } else if !c.Hidden { additionalCommands = append(additionalCommands, s) } }