Skip to content

Commit 28f91cb

Browse files
author
Nate Smith
authored
Merge pull request cli#1107 from vilmibm/move-credits
minor credits polish
2 parents cb4baae + 89830d8 commit 28f91cb

File tree

3 files changed

+45
-13
lines changed

3 files changed

+45
-13
lines changed

command/credits.go

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,22 @@ func init() {
4141
}
4242

4343
var creditsCmd = &cobra.Command{
44-
Use: "credits [repository]",
45-
Short: "View project's credits",
46-
Long: `View animated credits for this or another project.
47-
48-
Examples:
49-
50-
gh credits # see a credits animation for this project
44+
Use: "credits",
45+
Short: "View credits for this tool",
46+
Long: `View animated credits for gh, the tool you are currently using :)`,
47+
Example: `gh credits # see a credits animation for this project
5148
gh credits owner/repo # see a credits animation for owner/repo
5249
gh credits -s # display a non-animated thank you
5350
gh credits | cat # just print the contributors, one per line
5451
`,
55-
Args: cobra.MaximumNArgs(1),
56-
RunE: credits,
52+
Args: cobra.ExactArgs(0),
53+
RunE: ghCredits,
54+
Hidden: true,
55+
}
56+
57+
func ghCredits(cmd *cobra.Command, _ []string) error {
58+
args := []string{"cli/cli"}
59+
return credits(cmd, args)
5760
}
5861

5962
func credits(cmd *cobra.Command, args []string) error {
@@ -64,9 +67,18 @@ func credits(cmd *cobra.Command, args []string) error {
6467
return err
6568
}
6669

67-
owner := "cli"
68-
repo := "cli"
69-
if len(args) > 0 {
70+
var owner string
71+
var repo string
72+
73+
if len(args) == 0 {
74+
baseRepo, err := determineBaseRepo(client, cmd, ctx)
75+
if err != nil {
76+
return err
77+
}
78+
79+
owner = baseRepo.RepoOwner()
80+
repo = baseRepo.RepoName()
81+
} else {
7082
parts := strings.SplitN(args[0], "/", 2)
7183
owner = parts[0]
7284
repo = parts[1]

command/repo.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ func init() {
3838

3939
repoCmd.AddCommand(repoViewCmd)
4040
repoViewCmd.Flags().BoolP("web", "w", false, "Open a repository in the browser")
41+
42+
repoCmd.AddCommand(repoCreditsCmd)
43+
repoCreditsCmd.Flags().BoolP("static", "s", false, "Print a static version of the credits")
4144
}
4245

4346
var repoCmd = &cobra.Command{
@@ -92,6 +95,19 @@ With '--web', open the repository in a web browser instead.`,
9295
RunE: repoView,
9396
}
9497

98+
var repoCreditsCmd = &cobra.Command{
99+
Use: "credits [<repository>]",
100+
Short: "View credits for a repository",
101+
Example: `$ gh repo credits # view credits for the current repository
102+
$ gh repo credits cool/repo # view credits for cool/repo
103+
$ gh repo credits -s # print a non-animated thank you
104+
$ gh repo credits | cat # pipe to just print the contributors, one per line
105+
`,
106+
Args: cobra.MaximumNArgs(1),
107+
RunE: repoCredits,
108+
Hidden: true,
109+
}
110+
95111
func parseCloneArgs(extraArgs []string) (args []string, target string) {
96112
args = extraArgs
97113

@@ -597,3 +613,7 @@ func repoView(cmd *cobra.Command, args []string) error {
597613

598614
return nil
599615
}
616+
617+
func repoCredits(cmd *cobra.Command, args []string) error {
618+
return credits(cmd, args)
619+
}

command/root.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ func rootHelpFunc(command *cobra.Command, args []string) {
365365
s := " " + rpad(c.Name()+":", c.NamePadding()) + c.Short
366366
if includes(coreCommandNames, c.Name()) {
367367
coreCommands = append(coreCommands, s)
368-
} else if c != creditsCmd {
368+
} else if !c.Hidden {
369369
additionalCommands = append(additionalCommands, s)
370370
}
371371
}

0 commit comments

Comments
 (0)