Skip to content

Commit

Permalink
feat(completion): add fish and powershell support
Browse files Browse the repository at this point in the history
Signed-off-by: Alexey Igrychev <alexey.igrychev@flant.com>
  • Loading branch information
alexey-igrychev committed Nov 10, 2022
1 parent 2792565 commit b9d0b9d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
14 changes: 12 additions & 2 deletions cmd/werf/completion/completion.go
Expand Up @@ -28,7 +28,13 @@ func NewCmd(ctx context.Context, rootCmd *cobra.Command) *cobra.Command {
# Load zsh completion
$ autoload -Uz compinit && compinit -C
$ source <(%[1]s completion --shell=zsh)`, rootCmd.Name()),
$ source <(%[1]s completion --shell=zsh)
# Load fish completion
$ source <(%[1]s completion --shell=fish)
# Load powershell completion
$ %[1]s completion --shell=powershell | Out-String | Invoke-Expression`, rootCmd.Name()),
RunE: func(cmd *cobra.Command, args []string) error {
switch cmdData.Shell {
case "bash":
Expand All @@ -41,6 +47,10 @@ func NewCmd(ctx context.Context, rootCmd *cobra.Command) *cobra.Command {
_, _ = os.Stdout.WriteString(zshCompdef)

return nil
case "fish":
return rootCmd.GenFishCompletion(os.Stdout, true)
case "powershell":
return rootCmd.GenPowerShellCompletion(os.Stdout)
default:
common.PrintHelp(cmd)
return fmt.Errorf("provided shell %q not supported", cmdData.Shell)
Expand All @@ -55,7 +65,7 @@ func NewCmd(ctx context.Context, rootCmd *cobra.Command) *cobra.Command {
defaultShell = "bash"
}

cmd.Flags().StringVarP(&cmdData.Shell, "shell", "", defaultShell, "Set to bash or zsh (default $WERF_SHELL or bash)")
cmd.Flags().StringVarP(&cmdData.Shell, "shell", "", defaultShell, "Set to bash, zsh, fish or powershell (default $WERF_SHELL or bash)")

return cmd
}
8 changes: 7 additions & 1 deletion docs/_includes/reference/cli/werf_completion.md
Expand Up @@ -22,12 +22,18 @@ werf completion [options]
# Load zsh completion
$ autoload -Uz compinit && compinit -C
$ source <(werf completion --shell=zsh)

# Load fish completion
$ source <(werf completion --shell=fish)

# Load powershell completion
$ werf completion --shell=powershell | Out-String | Invoke-Expression
```

{{ header }} Options

```shell
--shell='bash'
Set to bash or zsh (default $WERF_SHELL or bash)
Set to bash, zsh, fish or powershell (default $WERF_SHELL or bash)
```

0 comments on commit b9d0b9d

Please sign in to comment.