Skip to content

feat: add shell completion scripts - #622

Merged
nklmilojevic merged 1 commit into
mainfrom
feat/shell-completion
Sep 16, 2026
Merged

nklmilojevic merged 1 commit into
mainfrom
feat/shell-completion

Conversation

@nklmilojevic

Copy link
Copy Markdown
Owner

Shell users cannot complete sofka CLI options or subcommands. Add sofka completion <shell> for Bash, Zsh, Fish, Elvish, and PowerShell, with scripts generated from the CLI definitions and setup instructions for each shell.

Generation exits before configuration loading, runtime startup, or cluster access. Live resource, namespace, and context values are outside this scope. Use --resource completion to open a resource with the same name.

Validation: just check; binary tests for all five script outputs, invalid or missing shell names, and generation with malformed local configuration. Bash, Zsh, and Fish script loading and completion checks also pass. Elvish and PowerShell are not installed locally, so their scripts have output checks only.

Agreed discussion: #620
Closes #621

Two concurrent pre-commit runs failed in the existing port_forward_picker_keeps_selection_when_local_port_is_in_use test. It passed in the first full run and in an isolated retry. No port-forward code was changed.

All pre-commit hooks passed with RUST_TEST_THREADS=1, including the complete test suite.

Generate completion scripts from the CLI definitions for Bash, Zsh, Fish, Elvish, and PowerShell. Shell users had no way to complete CLI options and subcommands. Exit before loading configuration or connecting to a cluster.

Closes #621
@greptile-apps

greptile-apps Bot commented Sep 16, 2026

Copy link
Copy Markdown

Greptile Summary

Adds a configuration-independent sofka completion <shell> command backed by clap_complete.

  • Generates completion scripts for Bash, Zsh, Fish, Elvish, and PowerShell directly from the Clap command definition.
  • Returns before runtime initialization, configuration loading, or Kubernetes access.
  • Documents shell-specific setup and the --resource completion escape hatch.
  • Adds binary-level coverage for every supported shell, malformed local configuration, and invalid or missing shell names.

Confidence Score: 5/5

The PR appears safe to merge; no actionable correctness, security, or repository-rule violations were identified.

Completion generation is reached immediately after parsing and exits before configuration or cluster initialization, while the reserved resource-name behavior and supported shell inputs are documented and tested.

Important Files Changed
Filename Overview
src/main.rs Adds the completion subcommand and an early generation path that bypasses normal runtime and cluster initialization.
tests/completion.rs Exercises all supported generators, malformed configuration isolation, and Clap errors for missing or unsupported shell names.
docs/shell-completion.md Documents startup configuration for all five shells and explains the command’s static-completion scope.
Cargo.toml Adds the clap_complete dependency used to generate scripts from the existing Clap definitions.
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A["Start sofka"] --> B["Parse CLI arguments"]
  B --> C{"completion subcommand?"}
  C -->|Yes| D["Build Clap command definition"]
  D --> E["Generate script for selected shell"]
  E --> F["Write script to stdout and exit"]
  C -->|No| G["Apply kubeconfig override"]
  G --> H["Create Tokio runtime"]
  H --> I["Load configuration and start normal CLI flow"]
Loading

Reviews (1): Last reviewed commit: "feat: add shell completion scripts" | Re-trigger Greptile

@nklmilojevic
nklmilojevic merged commit 310cf12 into main Sep 16, 2026
13 checks passed
@nklmilojevic
nklmilojevic deleted the feat/shell-completion branch September 16, 2026 21:10
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.

feat: add shell completion scripts

1 participant