Skip to content

Commit

Permalink
feat: support fish completion (#2929)
Browse files Browse the repository at this point in the history
* feat: support fish completion

* fix: fix help message

* fix(completion): fix help message
  • Loading branch information
suzuki-shunsuke authored May 31, 2024
1 parent a83c373 commit 9ff6537
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/wc-integration-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ jobs:
run: aqua completion bash
- name: output zsh completion
run: aqua completion zsh
- name: output fish completion
run: aqua completion fish

- run: aqua g -i suzuki-shunsuke/tfcmt
working-directory: tests/main
Expand Down
2 changes: 1 addition & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ brews:
# Template: allowed
# Since: v1.20
extra_install: |
generate_completions_from_executable(bin/"aqua", "completion", shells: [:bash, :zsh])
generate_completions_from_executable(bin/"aqua", "completion", shells: [:bash, :zsh, :fish])
scoops:
-
Expand Down
34 changes: 29 additions & 5 deletions pkg/cli/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,27 @@ func (r *Runner) newCompletionCommand() *cli.Command {
// https://cli.urfave.org/v2/#bash-completion
return &cli.Command{
Name: "completion",
Usage: "Output shell completion script for bash or zsh",
Description: `Output shell completion script for bash or zsh
Run these commands in .bash_profile or .zprofile
Usage: "Output shell completion script for bash, zsh, or fish",
Description: `Output shell completion script for bash, zsh, or fish.
Source the output to enable completion.
e.g.
.bash_profile
if command -v aqua &> /dev/null; then source <(aqua completion bash); fi
if command -v aqua &> /dev/null; then
source <(aqua completion bash)
fi
.zprofile
if command -v aqua &> /dev/null; then source <(aqua completion zsh); fi
if command -v aqua &> /dev/null; then
source <(aqua completion zsh)
fi
fish
aqua completion fish > ~/.config/fish/completions/aqua.fish
`,
Subcommands: []*cli.Command{
{
Expand All @@ -34,6 +44,11 @@ if command -v aqua &> /dev/null; then source <(aqua completion zsh); fi
Usage: "Output shell completion script for zsh",
Action: r.zshCompletionAction,
},
{
Name: "fish",
Usage: "Output shell completion script for fish",
Action: r.fishCompletionAction,
},
},
}
}
Expand Down Expand Up @@ -90,3 +105,12 @@ else
fi`)
return nil
}

func (r *Runner) fishCompletionAction(c *cli.Context) error {
s, err := c.App.ToFishCompletion()
if err != nil {
return fmt.Errorf("generate fish completion: %w", err)
}
fmt.Fprintln(r.Stdout, s)
return nil
}

0 comments on commit 9ff6537

Please sign in to comment.