From c09c2ad025ec63cf0313e91b36c91456a8516a96 Mon Sep 17 00:00:00 2001 From: vilmibm Date: Thu, 4 Jun 2020 16:38:03 -0500 Subject: [PATCH 1/8] shuffle around credits command so it makes more sense --- command/credits.go | 35 +++++++++++++++++++++++------------ command/repo.go | 19 +++++++++++++++++++ 2 files changed, 42 insertions(+), 12 deletions(-) diff --git a/command/credits.go b/command/credits.go index e0187adb7..84488a35a 100644 --- a/command/credits.go +++ b/command/credits.go @@ -41,19 +41,21 @@ 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, +} + +func ghCredits(cmd *cobra.Command, args []string) error { + args = []string{"cli/cli"} + return credits(cmd, args) } func credits(cmd *cobra.Command, args []string) error { @@ -64,9 +66,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 ad208a277..4e8935ec8 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{ @@ -89,6 +92,18 @@ With '--web', open the repository in a web browser instead.`, RunE: repoView, } +var repoCreditsCmd = &cobra.Command{ + Use: "credits [repository]", + 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, +} + func parseCloneArgs(extraArgs []string) (args []string, target string) { args = extraArgs @@ -587,3 +602,7 @@ func repoView(cmd *cobra.Command, args []string) error { return nil } + +func repoCredits(cmd *cobra.Command, args []string) error { + return credits(cmd, args) +} From bd4bac962a49e198648b88690d05857017a97763 Mon Sep 17 00:00:00 2001 From: vilmibm Date: Thu, 4 Jun 2020 16:42:32 -0500 Subject: [PATCH 2/8] use Annotations to hide commands --- command/credits.go | 1 + command/repo.go | 2 ++ command/root.go | 3 ++- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/command/credits.go b/command/credits.go index 84488a35a..e9e43b0c7 100644 --- a/command/credits.go +++ b/command/credits.go @@ -51,6 +51,7 @@ var creditsCmd = &cobra.Command{ `, Args: cobra.ExactArgs(0), RunE: ghCredits, + Annotations: map[string]string{"hidden":"true"}, } func ghCredits(cmd *cobra.Command, args []string) error { diff --git a/command/repo.go b/command/repo.go index 4e8935ec8..b3edbe6b7 100644 --- a/command/repo.go +++ b/command/repo.go @@ -102,6 +102,8 @@ $ gh repo credits | cat # pipe to just print the contributors, one per line `, Args: cobra.MaximumNArgs(1), RunE: repoCredits, + // NB will actually be hidden once https://github.com/cli/cli/pull/1106 is in + Annotations: map[string]string{"hidden":"true"}, } func parseCloneArgs(extraArgs []string) (args []string, target string) { diff --git a/command/root.go b/command/root.go index db76509ed..471168014 100644 --- a/command/root.go +++ b/command/root.go @@ -363,9 +363,10 @@ func rootHelpFunc(command *cobra.Command, args []string) { continue } s := " " + rpad(c.Name()+":", c.NamePadding()) + c.Short + _, hidden := c.Annotations["hidden"] if includes(coreCommandNames, c.Name()) { coreCommands = append(coreCommands, s) - } else if c != creditsCmd { + } else if !hidden { additionalCommands = append(additionalCommands, s) } } From 50335596ce247aff2e9e8688a6827d8c0c455a6f Mon Sep 17 00:00:00 2001 From: vilmibm Date: Thu, 4 Jun 2020 16:48:14 -0500 Subject: [PATCH 3/8] do not include hidden commands in generated docs --- cmd/gen-docs/main.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cmd/gen-docs/main.go b/cmd/gen-docs/main.go index 92581d07a..16b976f05 100644 --- a/cmd/gen-docs/main.go +++ b/cmd/gen-docs/main.go @@ -19,6 +19,12 @@ func main() { dir := docCmd.StringP("doc-path", "", "", "Path directory where you want generate doc files") help := docCmd.BoolP("help", "h", false, "Help about any command") + for _, cmd := range command.RootCmd.Commands() { + if _, hidden := cmd.Annotations["hidden"]; hidden { + command.RootCmd.RemoveCommand(cmd) + } + } + if err := docCmd.Parse(os.Args); err != nil { os.Exit(1) } From 1e25b0079a526ac225ade9f6614fe540be239d0c Mon Sep 17 00:00:00 2001 From: vilmibm Date: Thu, 4 Jun 2020 17:05:41 -0500 Subject: [PATCH 4/8] linter appeasement --- command/credits.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/command/credits.go b/command/credits.go index e9e43b0c7..189857fba 100644 --- a/command/credits.go +++ b/command/credits.go @@ -43,15 +43,15 @@ func init() { var creditsCmd = &cobra.Command{ Use: "credits", Short: "View credits for this tool", - Long: `View animated credits for gh, the tool you are currently using :)`, + 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.ExactArgs(0), - RunE: ghCredits, - Annotations: map[string]string{"hidden":"true"}, + Args: cobra.ExactArgs(0), + RunE: ghCredits, + Annotations: map[string]string{"hidden": "true"}, } func ghCredits(cmd *cobra.Command, args []string) error { @@ -71,13 +71,13 @@ func credits(cmd *cobra.Command, args []string) error { var repo string if len(args) == 0 { - baseRepo, err := determineBaseRepo(client, cmd, ctx) - if err != nil { + baseRepo, err := determineBaseRepo(client, cmd, ctx) + if err != nil { return err - } + } - owner = baseRepo.RepoOwner() - repo = baseRepo.RepoName() + owner = baseRepo.RepoOwner() + repo = baseRepo.RepoName() } else { parts := strings.SplitN(args[0], "/", 2) owner = parts[0] From 804ebf0d4d16cdeea1a7e5ef194485ee29ec6f07 Mon Sep 17 00:00:00 2001 From: vilmibm Date: Thu, 4 Jun 2020 17:07:16 -0500 Subject: [PATCH 5/8] linter appeasement --- command/repo.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/command/repo.go b/command/repo.go index b3edbe6b7..e98c8476b 100644 --- a/command/repo.go +++ b/command/repo.go @@ -93,7 +93,7 @@ With '--web', open the repository in a web browser instead.`, } var repoCreditsCmd = &cobra.Command{ - Use: "credits [repository]", + Use: "credits [repository]", 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 @@ -103,7 +103,7 @@ $ gh repo credits | cat # pipe to just print the contributors, one per line Args: cobra.MaximumNArgs(1), RunE: repoCredits, // NB will actually be hidden once https://github.com/cli/cli/pull/1106 is in - Annotations: map[string]string{"hidden":"true"}, + Annotations: map[string]string{"hidden": "true"}, } func parseCloneArgs(extraArgs []string) (args []string, target string) { From cea34755c74c3d942c24f141ac3f1d69da8b5e1c Mon Sep 17 00:00:00 2001 From: vilmibm Date: Thu, 4 Jun 2020 17:09:42 -0500 Subject: [PATCH 6/8] linter appeasement --- command/credits.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/command/credits.go b/command/credits.go index 189857fba..cdaeff0f3 100644 --- a/command/credits.go +++ b/command/credits.go @@ -54,8 +54,8 @@ var creditsCmd = &cobra.Command{ Annotations: map[string]string{"hidden": "true"}, } -func ghCredits(cmd *cobra.Command, args []string) error { - args = []string{"cli/cli"} +func ghCredits(cmd *cobra.Command, _ []string) error { + args := []string{"cli/cli"} return credits(cmd, args) } From e2ef712e439101cb2aa8810c44f4c7e515d66af4 Mon Sep 17 00:00:00 2001 From: vilmibm Date: Mon, 8 Jun 2020 12:31:40 -0500 Subject: [PATCH 7/8] use Command.Hidden --- cmd/gen-docs/main.go | 6 ------ command/credits.go | 6 +++--- command/repo.go | 7 +++---- command/root.go | 3 +-- 4 files changed, 7 insertions(+), 15 deletions(-) diff --git a/cmd/gen-docs/main.go b/cmd/gen-docs/main.go index 16b976f05..92581d07a 100644 --- a/cmd/gen-docs/main.go +++ b/cmd/gen-docs/main.go @@ -19,12 +19,6 @@ func main() { dir := docCmd.StringP("doc-path", "", "", "Path directory where you want generate doc files") help := docCmd.BoolP("help", "h", false, "Help about any command") - for _, cmd := range command.RootCmd.Commands() { - if _, hidden := cmd.Annotations["hidden"]; hidden { - command.RootCmd.RemoveCommand(cmd) - } - } - if err := docCmd.Parse(os.Args); err != nil { os.Exit(1) } diff --git a/command/credits.go b/command/credits.go index cdaeff0f3..9d5560bad 100644 --- a/command/credits.go +++ b/command/credits.go @@ -49,9 +49,9 @@ var creditsCmd = &cobra.Command{ gh credits -s # display a non-animated thank you gh credits | cat # just print the contributors, one per line `, - Args: cobra.ExactArgs(0), - RunE: ghCredits, - Annotations: map[string]string{"hidden": "true"}, + Args: cobra.ExactArgs(0), + RunE: ghCredits, + Hidden: true, } func ghCredits(cmd *cobra.Command, _ []string) error { diff --git a/command/repo.go b/command/repo.go index e98c8476b..08eb1d490 100644 --- a/command/repo.go +++ b/command/repo.go @@ -100,10 +100,9 @@ $ 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, - // NB will actually be hidden once https://github.com/cli/cli/pull/1106 is in - Annotations: map[string]string{"hidden": "true"}, + Args: cobra.MaximumNArgs(1), + RunE: repoCredits, + Hidden: true, } func parseCloneArgs(extraArgs []string) (args []string, target string) { diff --git a/command/root.go b/command/root.go index 471168014..dcabedf13 100644 --- a/command/root.go +++ b/command/root.go @@ -363,10 +363,9 @@ func rootHelpFunc(command *cobra.Command, args []string) { continue } s := " " + rpad(c.Name()+":", c.NamePadding()) + c.Short - _, hidden := c.Annotations["hidden"] if includes(coreCommandNames, c.Name()) { coreCommands = append(coreCommands, s) - } else if !hidden { + } else if !c.Hidden { additionalCommands = append(additionalCommands, s) } } From 89830d86d19a8dceed501ef7e6bcdda33b53fb02 Mon Sep 17 00:00:00 2001 From: vilmibm Date: Mon, 8 Jun 2020 12:32:51 -0500 Subject: [PATCH 8/8] correct usage --- command/repo.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/command/repo.go b/command/repo.go index 08eb1d490..32f9afa27 100644 --- a/command/repo.go +++ b/command/repo.go @@ -93,7 +93,7 @@ With '--web', open the repository in a web browser instead.`, } var repoCreditsCmd = &cobra.Command{ - Use: "credits [repository]", + 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