Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add completion for fish #96

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat: add completion for fish
  • Loading branch information
zeekrs committed Jan 9, 2024
commit 3639d23dccd33e0d3d4ad9f0902d8f29a9cd4b71
17 changes: 14 additions & 3 deletions cmd/hostctl/actions/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ import (

func newCompletionCmd(rootCmd *cobra.Command) *cobra.Command {
completionCmd := &cobra.Command{
Use: "completion <bash|zsh>",
Short: "Generate bash or zsh completion script",
Use: "completion <bash|zsh|fish>",
Short: "Generate bash zsh or fish completion script",
Hidden: true,
}

bashCompletionCmd := newBashCompletionCmd(rootCmd)
zshCompletionCmd := newZshCompletionCmd(rootCmd)
completionCmd.AddCommand(bashCompletionCmd, zshCompletionCmd)
fishCompletionCmd := newFishCompletionCmd(rootCmd)
completionCmd.AddCommand(bashCompletionCmd, zshCompletionCmd, fishCompletionCmd)

return completionCmd
}
Expand All @@ -39,3 +40,13 @@ func newZshCompletionCmd(rootCmd *cobra.Command) *cobra.Command {
},
}
}

func newFishCompletionCmd(rootCmd *cobra.Command) *cobra.Command {
return &cobra.Command{
Use: "fish",
Short: "Generate fish completion script",
RunE: func(cmd *cobra.Command, args []string) error {
return rootCmd.GenFishCompletion(os.Stdout, true)
},
}
}