Skip to content

feat: add partial context matching to switch command#2

Merged
davidblum merged 4 commits intomasterfrom
dblum/partial-input-filtering
Mar 27, 2026
Merged

feat: add partial context matching to switch command#2
davidblum merged 4 commits intomasterfrom
dblum/partial-input-filtering

Conversation

@davidblum
Copy link
Copy Markdown
Owner

Overview

Adds partial context matching to the switch command. When a context argument is provided, it first tries an exact match (switches immediately without the picker). If no exact match, it filters contexts by case-insensitive substring and opens the fuzzy picker with only the matches.

Based on the store-env-vars branch (#1), so includes KUBESWITCH_STORE and KUBESWITCH_PATH support.

Originally submitted upstream as danielfoehrKn#194, rebased onto the store-env-vars work.

Technical

  • Adds desiredContext parameter to Switcher() function
  • Routes args through Switcher() instead of setContextCmd for unified handling
  • Exact match: bypasses fuzzy picker entirely
  • Partial match: filters the global context list, then opens the picker with reduced set
  • waitForSearchResults() helper ensures async search has populated before matching
  • All return paths include store name and source path (from feat: expose store name and source path as env vars #1)

Testing

  • go build ./... passes
  • go test ./... passes
  • switch aws-otk-prod-dx-use1-004 switches immediately (exact match)
  • switch prod-dx opens picker filtered to matching contexts (partial match)
  • switch nonexistent returns error "no contexts matching"
  • switch with no args opens normal fuzzy picker (unchanged behavior)
  • KUBESWITCH_STORE and KUBESWITCH_PATH set correctly for all paths

When running `switch <name>`, the tool now supports partial matching:
- Exact match: switches immediately (preserves existing behavior)
- Partial match: opens fuzzy finder pre-filtered to matching contexts
- No match: returns helpful error message

Matching is case-insensitive for partial matches and searches both
context names and aliases.
@davidblum davidblum self-assigned this Mar 27, 2026
@davidblum davidblum merged commit 730e04f into master Mar 27, 2026
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.

1 participant