Skip to content

✨ feat(cli): complete --context/--format/--log-level flags - #288

Merged
konih merged 1 commit into
mainfrom
feat/pipe-complete-01-flag-completion
Aug 10, 2026
Merged

konih merged 1 commit into
mainfrom
feat/pipe-complete-01-flag-completion

Conversation

@Xiilent

@Xiilent Xiilent commented Aug 9, 2026

Copy link
Copy Markdown

--context typos are a fatal error at run time (resolveContexts, cmd/cli/context.go); completing the flag from the same kubeconfig the run itself resolves catches the typo in the shell instead. --format and --log-level get their fixed value sets. cobra 1.10.2 already ships the completion command (PIPE-COMPLETE-01) — this wires the missing flag value completion onto collect and init.

@Xiilent
Xiilent requested a review from konih as a code owner August 9, 2026 09:20
@codecov

codecov Bot commented Aug 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

--context typos are a fatal error at run time (resolveContexts,
cmd/cli/context.go); completing the flag from the same kubeconfig the
run itself resolves catches the typo in the shell instead. --format and
--log-level get their fixed value sets. cobra 1.10.2 already ships the
completion command (PIPE-COMPLETE-01) — this wires the missing flag
value completion onto collect and init.
@konih
konih force-pushed the feat/pipe-complete-01-flag-completion branch from 3bb810c to 9efceb6 Compare August 10, 2026 14:17

@konih konih left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

REVIEW: APPROVE (external-contributor path — reviewed per /merge-open-prs Step 3)

Correctness

  • contextCompletionFunc degrades correctly on a missing/unreadable kubeconfig: it returns nil, ShellCompDirectiveNoFileComp instead of surfacing an error. Nothing is written to stdout and there is no panic path, so the shell completion stream cannot be corrupted — the main failure mode for dynamic completion.
  • Completion resolves the kubeconfig through the same effectiveKubeconfigPath the run itself uses (flag → $KUBECONFIG → RecommendedHomeFile), so a suggestion cannot disagree with what resolveContexts will later accept. That is the point of the story, and it is wired correctly.
  • registerContextCompletion is applied to init as well as collect. Verified init declares both --context and --kubeconfig (cmd/cli/init.go:51,53), so the GetString("kubeconfig") lookup resolves rather than quietly falling back to the default.
  • Comma-segment handling (--context a,pro<TAB>) re-prepends the leading segment, so multi-context completion emits full flag values rather than bare names.

Tests — cover the fixed value sets, the dynamic path, prefix filtering, and the comma-segment case. TestLogLevelCompletions_matchesLogLevelsMap asserts both directions against the logLevels map, so a future log level cannot drift out of completion silently. Good invariant to pick.

Non-blocking note — a colon-separated $KUBECONFIG list will fail LoadFromFile and yield no completions. That limitation is pre-existing in the run path itself, not introduced here.

CI green across all checks.

@sonarqubecloud

Copy link
Copy Markdown

@konih
konih merged commit 8958d66 into main Aug 10, 2026
36 checks passed
@konih
konih deleted the feat/pipe-complete-01-flag-completion branch August 10, 2026 14:25
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