From 4e97f5c6e1f89b5686e479feb6721a3b5857d1ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20K=C3=A4mmerling?= Date: Tue, 6 Apr 2021 13:20:03 +0200 Subject: [PATCH] Add Powershell completion (#316) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Lukas Kämmerling --- README.md | 13 ++++++++++++- internal/cmd/completion/completion.go | 15 ++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 00ad69fa..d2a7fd0a 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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: diff --git a/internal/cmd/completion/completion.go b/internal/cmd/completion/completion.go index bd876e16..604227d3 100644 --- a/internal/cmd/completion/completion.go +++ b/internal/cmd/completion/completion.go @@ -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 @@ -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]) }