kubectl: forward --context and --cluster into completion generators - #332
Closed
warp-agent-staging[bot] wants to merge 3 commits into
Closed
kubectl: forward --context and --cluster into completion generators#332warp-agent-staging[bot] wants to merge 3 commits into
warp-agent-staging[bot] wants to merge 3 commits into
Conversation
Contributor
Author
|
This PR was generated with Warp. |
4 tasks
The kubectl generators build their query command from the tokens already
on the line so completions are scoped to what the user has typed. Only
--kubeconfig and --namespace/-n were forwarded, so a --context (or
--cluster) written on the command line was dropped: with
kubectl --context staging-cluster --namespace <TAB>
the generated command was
kubectl ... get namespace -o custom-columns=:.metadata.name
which enumerates namespaces from the shell's active context rather than
from staging-cluster. Forward both flags, mirroring the existing
--kubeconfig and --namespace handling.
Forwarded values are now double-quoted. Tokens reach generators with
their shell quoting already stripped, so a value containing whitespace
previously split into multiple arguments and produced a broken command.
Tests now assert the forwarded flags in the generated command, including
one assertion on the full command string, and
test_context_and_namespace_flags_before_subcommand -- which passed a
--context but only checked namespace forwarding -- now checks both so
the gap cannot silently reopen.
Co-Authored-By: Warp Agent <agent@warp.dev>
`kubectl --user <TAB>` had no generator, so it fell back to file path completions. `kubectl config get-users` lists the users defined in the kubeconfig; wire it up the same way `--cluster` uses `config get-clusters`, filtering out the "NAME" header since `config get-users` has no `-o name` form. Co-Authored-By: Warp Agent <agent@warp.dev>
Both specs declare persistent --context, --cluster and --user options with no generatorName, so `kubecolor get --context <TAB>` fell back to file path completions -- the un-migrated version of what #247 fixed for kubectl. Both already register kubectl's generators, so this is spec wiring plus registering the new `user` generator. Note this commit depends on the preceding `user` generator commit; dropping that one requires dropping the --user lines here too. Co-Authored-By: Warp Agent <agent@warp.dev>
warp-agent-staging
Bot
force-pushed
the
factory/app-46-kubectl-context-forwarding
branch
from
August 13, 2026 23:31
24f7cca to
c85b0a9
Compare
warp-agent-staging Bot
pushed a commit
to warpdotdev/warp
that referenced
this pull request
Aug 13, 2026
Picks up warpdotdev/command-signatures#332, which forwards a --context or --cluster written on the command line into the commands the kubectl completion generators run. Without it, completions after a --context enumerated from the shell's active context instead of the one on the line (#5186, #3929). Co-Authored-By: Warp Agent <agent@warp.dev>
Contributor
Author
|
Consolidated into #331, which fixes the same gap and was opened first. Its unique parts — the Responding as wilson: Open session · View factory task |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Description
The kubectl generators build their query command from the tokens already on the line, so completions are scoped to what the user has typed. Only
--kubeconfigand--namespace/-nwere forwarded, so a--context(or--cluster) written on the command line was silently dropped. Withthe generated command was
kubectl … get namespace -o custom-columns=:.metadata.name— no--context— so the suggestions came from the shell's active context rather than fromstaging-cluster. The same omission affected the resource and api-resources generators.This is the one remaining symptom of warpdotdev/warp#5186 (the
--context/--clustervalue completions themselves were fixed by #247), and it is what warpdotdev/warp#3929 asks for directly (kubectl --context staging-cluster -n project1 get pods).Changes
Three independent commits, in order:
kubectl: forward--contextand--cluster— mirrors the existing--kubeconfig/--namespacehandling viaspace_or_equals_delimited_option_value, so both--flag valueand--flag=valuework. Forwarded values are now shell-quoted: tokens reach generators with their shell quoting already stripped, so a value containing whitespace previously split into multiple arguments and produced a broken command. Quoting uses single quotes with'escaped as'\'', the techniquegit.rsandscp.rsalready use for interpolated token values, which also neutralizes$, backticks and backslashes.kubectl: complete--uservalues —kubectl --user <TAB>had no generator and fell back to file paths;kubectl config get-userssupplies them.kubecolor,oc: complete--context,--clusterand--uservalues — both specs declare these as persistent options with nogeneratorNamedespite already registering kubectl's generators, sokubecolor get --context <TAB>still showed file paths. This is the un-migrated version of what Fix kubectl --context and --cluster persistent flag completions #247 fixed for kubectl. Commit 3 depends on commit 2 for theusergenerator; dropping commit 2 means dropping the--userlines in commit 3 as well.Commits 2 and 3 are drive-by wiring — drop either without affecting the fix in commit 1.
Overlap with #331
#331 was opened ~15 minutes before this PR and independently fixes the same
--context/--clusterforwarding gap, plus--user. Only one of these should land. The differences, so a reviewer can pick quickly:space_or_equals_delimited_option_valuetake the last occurrence of a repeated flag and stop at a bare--, matching pflag semantics. That is a genuine improvement this PR does not have.--user; this PR deliberately only adds--uservalue completion.--context/--cluster/--userforkubecolorandoc, which Forward --context/--cluster/--user in kubectl generators #331 does not touch, and asserts the full generated command string for the reported case.If #331 lands, the useful remainder of this PR is its third commit (kubecolor/oc wiring) plus the full-command test, which can be rebased on top. The companion rev bump in warpdotdev/warp needs to be re-pointed at whichever commit lands.
Notes
--context/--clustervalue completion. While completing those values the partial value gets forwarded intoconfig get-contexts/get-clusters, which kubectl accepts and still answers with the full list (exit 0).--useris deliberately not forwarded into the generated commands; only its own value completion is added. Forwarding it was outside the scope of this fix.oc, the context/cluster/user generators runkubectl(they are kubectl's generators, shared). That matches howoc's existing--namespacegenerator already behaves.Testing
./script/presubmitpasses: prettier JSON check,cargo fmt,cargo clippy --all-targets --all-features -D warnings, andcargo test(161 tests).New and tightened tests assert the generated command, not merely that completion happens:
test_full_generated_command_forwards_context_to_namespace_queryasserts the complete command string for the reported case.test_context_long_flag_before_subcommand,test_context_flag_after_subcommand,test_context_equals_syntax,test_cluster_flag_forwarded,test_cluster_equals_syntax.test_no_flags_forwarded_when_absent,test_forwarded_values_with_whitespace_are_quoted,test_forwarded_value_with_single_quote_is_escapedandtest_forwarded_value_does_not_expand_shell_metacharacters.test_context_and_namespace_flags_before_subcommandalready passed a--contextbut only asserted namespace forwarding, leaving the gap unasserted. It now checks both, so the gap cannot silently reopen.No visual capture was taken. Verifying this in a running client means building the full Warp client against a bumped
warp-command-signaturesrev, which is expensive relative to the value here; #247 already carries screenshots of the--context/--clustervalue completion working, and the assertions above cover the generated command precisely.A follow-up PR in
warpdotdev/warpbumps the pinnedwarp-command-signaturesrev so this reaches the client.