mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-12 10:55:20 +02:00
67bcada96a
* fix(deps): update module github.com/hashicorp/vault to v1.13.5 [security] * fix(deps): update module github.com/Azure/azure-sdk-for-go/tree/sdk/storage/azblob to v0.4.1 * fix(deps): update module github.com/hashicorp/vault/sdk to v0.9.2 fix(deps): update module oras.land/oras-go to v1.2.3 * fix(deps): update module github.com/hashicorp/vault/sdk to v0.9.2-0.20230530190758-08ee474850e0 fix(deps): update module github.com/hashicorp/vault/sdk to v0.9.2-0.20230530190758-08ee474850e0 * replacing deprecated function --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Muhammadali Nazarov <muhammadalinazarov@gmail.com> Co-authored-by: Jordi van Liempt <35920075+jliempt@users.noreply.github.com>
63 lines
1.7 KiB
Go
63 lines
1.7 KiB
Go
package cmd
|
|
|
|
import (
|
|
"os"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
// CommandLineCompletionCommand allows to generate convenience scripts for using the piper cli in a shell.
|
|
// See https://github.com/spf13/cobra/blob/master/shell_completions.md for docs on the subject.
|
|
func CommandLineCompletionCommand() *cobra.Command {
|
|
return &cobra.Command{
|
|
Use: "completion [bash|zsh|fish|powershell]",
|
|
Short: "Generate completion script",
|
|
Long: `To load completions:
|
|
|
|
Bash:
|
|
|
|
$ source <(piper completion bash)
|
|
|
|
# To load completions for each session, execute once:
|
|
Linux:
|
|
$ piper completion bash > /etc/bash_completion.d/piper
|
|
MacOS:
|
|
$ piper completion bash > /usr/local/etc/bash_completion.d/piper
|
|
|
|
Zsh:
|
|
|
|
# If shell completion is not already enabled in your environment you will need
|
|
# to enable it. You can execute the following once:
|
|
|
|
$ echo "autoload -U compinit; compinit" >> ~/.zshrc
|
|
|
|
# To load completions for each session, execute once:
|
|
$ piper completion zsh > "${fpath[1]}/_piper"
|
|
|
|
# You will need to start a new shell for this setup to take effect.
|
|
|
|
Fish:
|
|
|
|
$ piper completion fish | source
|
|
|
|
# To load completions for each session, execute once:
|
|
$ piper completion fish > ~/.config/fish/completions/piper.fish
|
|
`,
|
|
DisableFlagsInUseLine: true,
|
|
ValidArgs: []string{"bash", "zsh", "fish", "powershell"},
|
|
Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs),
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
switch args[0] {
|
|
case "bash":
|
|
_ = cmd.Root().GenBashCompletion(os.Stdout)
|
|
case "zsh":
|
|
_ = cmd.Root().GenZshCompletion(os.Stdout)
|
|
case "fish":
|
|
_ = cmd.Root().GenFishCompletion(os.Stdout, true)
|
|
case "powershell":
|
|
_ = cmd.Root().GenPowerShellCompletion(os.Stdout)
|
|
}
|
|
},
|
|
}
|
|
}
|