Repository navigation
✨ feat(cli): complete --context/--format/--log-level flags - #288
Conversation
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.
3bb810c to
9efceb6
Compare
konih
left a comment
There was a problem hiding this comment.
REVIEW: APPROVE (external-contributor path — reviewed per /merge-open-prs Step 3)
Correctness
contextCompletionFuncdegrades correctly on a missing/unreadable kubeconfig: it returnsnil, ShellCompDirectiveNoFileCompinstead 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
effectiveKubeconfigPaththe run itself uses (flag →$KUBECONFIG→RecommendedHomeFile), so a suggestion cannot disagree with whatresolveContextswill later accept. That is the point of the story, and it is wired correctly. registerContextCompletionis applied toinitas well ascollect. Verifiedinitdeclares both--contextand--kubeconfig(cmd/cli/init.go:51,53), so theGetString("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.
|



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