Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions command/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://docs.brew.sh/Shell-Completion>
`,
RunE: func(cmd *cobra.Command, args []string) error {
shellType, err := cmd.Flags().GetString("shell")
Expand All @@ -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:
Expand Down
11 changes: 11 additions & 0 deletions command/completion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"` {
Expand Down