From aa07c5366eebc5498f4993afda7e6a26ebb5545f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Thu, 5 Mar 2020 09:33:49 +0100 Subject: [PATCH 1/2] Add support for PowerShell completion --- command/completion.go | 2 ++ command/completion_test.go | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/command/completion.go b/command/completion.go index d225082ef..866a9c3cf 100644 --- a/command/completion.go +++ b/command/completion.go @@ -36,6 +36,8 @@ When installing with Homebrew, see https://docs.brew.sh/Shell-Completion return RootCmd.GenBashCompletion(cmd.OutOrStdout()) case "zsh": return RootCmd.GenZshCompletion(cmd.OutOrStdout()) + case "powershell": + return RootCmd.GenPowerShellCompletion(cmd.OutOrStdout()) case "fish": return cobrafish.GenCompletion(RootCmd, cmd.OutOrStdout()) default: diff --git a/command/completion_test.go b/command/completion_test.go index e8a15db56..49ca8c4db 100644 --- a/command/completion_test.go +++ b/command/completion_test.go @@ -38,6 +38,17 @@ func TestCompletion_fish(t *testing.T) { } } +func TestCompletion_powerShell(t *testing.T) { + output, err := RunCommand(completionCmd, `completion -s powershell`) + if err != nil { + t.Fatal(err) + } + + if !strings.Contains(output.String(), "Register-ArgumentCompleter") { + t.Errorf("problem in fish completion:\n%s", output) + } +} + func TestCompletion_unsupported(t *testing.T) { _, err := RunCommand(completionCmd, `completion -s csh`) if err == nil || err.Error() != `unsupported shell type "csh"` { From fa595596de2bd4f3fcb1cd51a029dff6311150eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Thu, 5 Mar 2020 09:34:05 +0100 Subject: [PATCH 2/2] Improve `completion` docs --- command/completion.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/command/completion.go b/command/completion.go index 866a9c3cf..94c9ccf5d 100644 --- a/command/completion.go +++ b/command/completion.go @@ -9,21 +9,21 @@ import ( func init() { RootCmd.AddCommand(completionCmd) - completionCmd.Flags().StringP("shell", "s", "bash", "The type of shell") + completionCmd.Flags().StringP("shell", "s", "bash", "Shell type: {bash|zsh|fish|powershell}") } var completionCmd = &cobra.Command{ - Use: "completion", - Hidden: true, - Short: "Generates completion scripts", - Long: `To enable completion in your shell, run: + Use: "completion", + Short: "Generate shell completion scripts", + Long: `Generate shell completion scripts for GitHub CLI commands. - eval "$(gh completion)" +For example, for bash you could add this to your '~/.bash_profile': -You can add that to your '~/.bash_profile' to enable completion whenever you -start a new shell. + eval "$(gh completion)" -When installing with Homebrew, see https://docs.brew.sh/Shell-Completion +When installing GitHub CLI through a package manager, however, it's possible that +no additional shell configuration is necessary to gain completion support. For +Homebrew, see `, RunE: func(cmd *cobra.Command, args []string) error { shellType, err := cmd.Flags().GetString("shell")