Skip to content

Commit

Permalink
Add Powershell completion (#316)
Browse files Browse the repository at this point in the history
Signed-off-by: Lukas Kämmerling <[email protected]>
  • Loading branch information
LKaemmerling authored Apr 6, 2021
1 parent b93bb4f commit 4e97f5c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ To load completions for each session execute the following commands:
mkdir -p ~/.config/hcloud/completion/zsh
hcloud completion zsh > ~/.config/hcloud/completion/zsh/_hcloud

Finally add the following line to your `~/.zshrc` file, *before* you
Finally, add the following line to your `~/.zshrc` file, *before* you
call the `compinit` function:

fpath+=(~/.config/hcloud/completion/zsh)
Expand All @@ -107,6 +107,17 @@ In order to make the completions permanent execute once:

hcloud completion fish > ~/.config/fish/completions/hcloud.fish

### PowerShell:

To load completions into the current shell execute:

PS> hcloud completion powershell | Out-String | Invoke-Expression

To load completions for every new session, run
and source this file from your PowerShell profile.

PS> hcloud completion powershell > hcloud.ps1

## Output configuration

You can control output via the `-o` option:
Expand Down
15 changes: 14 additions & 1 deletion internal/cmd/completion/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,20 @@ To load completions into the current shell execute:
In order to make the completions permanent execute once:
hcloud completion fish > ~/.config/fish/completions/hcloud.fish
### PowerShell:
To load completions into the current shell execute:
PS> hcloud completion powershell | Out-String | Invoke-Expression
To load completions for every new session, run
and source this file from your PowerShell profile.
PS> hcloud completion powershell > hcloud.ps1
`,
Args: cobra.ExactArgs(1),
ValidArgs: []string{"bash", "fish", "zsh"},
ValidArgs: []string{"bash", "fish", "zsh", "powershell"},
DisableFlagsInUseLine: true,
RunE: func(cmd *cobra.Command, args []string) error {
var err error
Expand All @@ -95,6 +106,8 @@ In order to make the completions permanent execute once:
err = cmd.Root().GenFishCompletion(os.Stdout, true)
case "zsh":
err = cmd.Root().GenZshCompletion(os.Stdout)
case "powershell":
err = cmd.Root().GenPowerShellCompletion(os.Stdout)
default:
err = fmt.Errorf("Unsupported shell: %s", args[0])
}
Expand Down

0 comments on commit 4e97f5c

Please sign in to comment.