Skip to content

Add shell completions command#45

Closed
vills wants to merge 1 commit intoserverscom:mainfrom
vills:feature/shell-completion
Closed

Add shell completions command#45
vills wants to merge 1 commit intoserverscom:mainfrom
vills:feature/shell-completion

Conversation

@vills
Copy link

@vills vills commented Feb 2, 2026

cobra natively supports shell completions generation. let's use it.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 completion subcommand 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/docgen mechanism (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]",
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
Use: "completions [bash|zsh|fish|powershell]",
Use: "completions SHELL",

Copilot uses AI. Check for mistakes.
Comment on lines +77 to +81
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] {
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.

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.
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"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.

Suggested change
Supported shells: bash, zsh, fish, and powershell.
Supported shells: bash, zsh, fish, and PowerShell.

Copilot uses AI. Check for mistakes.
@olegy89
Copy link
Collaborator

olegy89 commented Feb 2, 2026

It's already added by default:
srvctl completion

@olegy89 olegy89 closed this Feb 2, 2026
@vills
Copy link
Author

vills commented Feb 3, 2026

oh. i can see it now in srvctl --help command. but nothing about this in man or markdown pages. thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants