Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds a dedicated srvctl completions command and accompanying docs to generate shell completion scripts using Cobra’s built-in support.
Changes:
- Introduces a new
completionsubcommand wired into the root Cobra command, generating completion scripts for bash, zsh, fish, and PowerShell. - Adds human-facing documentation for the new command under
docs/srvctl-completions/, including descriptions and usage examples for different shells. - Integrates the new command into existing documentation generation via the existing
internal/docgenmechanism (through the new docs directory structure).
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| cmd/root.go | Registers the new completions subcommand with the root CLI, exposing srvctl completions to users. |
| cmd/completion/completion.go | Implements the srvctl completions Cobra command, argument validation, and dispatch to Cobra’s completion generators for supported shells. |
| docs/srvctl-completions/description.md | Provides a short description and supported shell list for the srvctl completions command, used by the doc generator. |
| docs/srvctl-completions/examples.md | Documents concrete examples for loading and installing completions across bash, zsh, fish, and PowerShell. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // NewCmd creates the completion command | ||
| func NewCmd() *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "completions [bash|zsh|fish|powershell]", |
There was a problem hiding this comment.
The Use string shows the shell argument in square brackets ([bash|zsh|fish|powershell]), which conventionally indicates an optional argument, but the command enforces cobra.ExactArgs(1) so the shell is actually required. To avoid confusing users and keep the CLI contract clear, consider updating the usage line to use a required placeholder (for example, completions SHELL) or relaxing the arg validation if you intend the argument to be optional.
| Use: "completions [bash|zsh|fish|powershell]", | |
| Use: "completions SHELL", |
| ValidArgs: []string{"bash", "zsh", "fish", "powershell"}, | ||
| Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs), | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| rootCmd := cmd.Root() | ||
| switch args[0] { |
There was a problem hiding this comment.
Given that Args uses cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs), args[0] can only ever be one of the four valid shells, so the default branch in the switch below is effectively unreachable. To simplify the control flow, either drop cobra.OnlyValidArgs and rely on the default case for validation, or keep OnlyValidArgs and remove the dead default branch.
|
|
||
| Shell completions provide command and flag suggestions when pressing Tab in your terminal, making it easier to discover and use srvctl commands. | ||
|
|
||
| Supported shells: bash, zsh, fish, and powershell. |
There was a problem hiding this comment.
"powershell" is capitalized inconsistently with the rest of the docs (and the official name), which use "PowerShell". Consider updating this line to use "PowerShell" for consistency and correctness.
| Supported shells: bash, zsh, fish, and powershell. | |
| Supported shells: bash, zsh, fish, and PowerShell. |
|
It's already added by default: |
|
oh. i can see it now in |
cobra natively supports shell completions generation. let's use it.