Skip to content

Commit b9d0b9d

Browse files
feat(completion): add fish and powershell support
Signed-off-by: Alexey Igrychev <alexey.igrychev@flant.com>
1 parent 2792565 commit b9d0b9d

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

cmd/werf/completion/completion.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,13 @@ func NewCmd(ctx context.Context, rootCmd *cobra.Command) *cobra.Command {
2828
2929
# Load zsh completion
3030
$ autoload -Uz compinit && compinit -C
31-
$ source <(%[1]s completion --shell=zsh)`, rootCmd.Name()),
31+
$ source <(%[1]s completion --shell=zsh)
32+
33+
# Load fish completion
34+
$ source <(%[1]s completion --shell=fish)
35+
36+
# Load powershell completion
37+
$ %[1]s completion --shell=powershell | Out-String | Invoke-Expression`, rootCmd.Name()),
3238
RunE: func(cmd *cobra.Command, args []string) error {
3339
switch cmdData.Shell {
3440
case "bash":
@@ -41,6 +47,10 @@ func NewCmd(ctx context.Context, rootCmd *cobra.Command) *cobra.Command {
4147
_, _ = os.Stdout.WriteString(zshCompdef)
4248

4349
return nil
50+
case "fish":
51+
return rootCmd.GenFishCompletion(os.Stdout, true)
52+
case "powershell":
53+
return rootCmd.GenPowerShellCompletion(os.Stdout)
4454
default:
4555
common.PrintHelp(cmd)
4656
return fmt.Errorf("provided shell %q not supported", cmdData.Shell)
@@ -55,7 +65,7 @@ func NewCmd(ctx context.Context, rootCmd *cobra.Command) *cobra.Command {
5565
defaultShell = "bash"
5666
}
5767

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

6070
return cmd
6171
}

docs/_includes/reference/cli/werf_completion.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,18 @@ werf completion [options]
2222
# Load zsh completion
2323
$ autoload -Uz compinit && compinit -C
2424
$ source <(werf completion --shell=zsh)
25+
26+
# Load fish completion
27+
$ source <(werf completion --shell=fish)
28+
29+
# Load powershell completion
30+
$ werf completion --shell=powershell | Out-String | Invoke-Expression
2531
```
2632

2733
{{ header }} Options
2834

2935
```shell
3036
--shell='bash'
31-
Set to bash or zsh (default $WERF_SHELL or bash)
37+
Set to bash, zsh, fish or powershell (default $WERF_SHELL or bash)
3238
```
3339

0 commit comments

Comments
 (0)