Repository navigation
kubectl: read kuberc alias flag groups, and give a short flag's value the next word whole (#140) - #145
Merged
Conversation
Fifteen of the new cases fail on main: a kuberc alias whose prependArgs or appendArgs hold a short flag group that sets -n, -s or -A is not noticed; the user's flags after an alias of logs are read with the wrong letters; and a value letter's next word (-c -n x, -f -n, -c --) is read as a flag. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
pflag (parseSingleShortArg) gives a value letter that ends its word the next word, whatever it holds: in `kubectl logs -c -n x` the container is "-n" and x is a positional argument, so the namespace is not x. The split now handles a lone value letter too and joins a value taken from the next word to its flag (`-c=-n`), so `flag` and `allNamespaces` can't read it as a flag, and a `--` taken as a value doesn't end the flags. The global long flags cloudpin knows take a value (VALUE_FLAGS) are joined the same way; kubectl's per-command long flags (--container -n x) are left open. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A kuberc alias's prependArgs and appendArgs were checked by their first letter only, so `-itnprod`, `-itn prod` or `-iA` set the namespace without cloudpin noticing. Each list is now split as pflag reads it, with the letters of the alias's command (its `command` field's first word, since logs and proxy change what -f, -p and -w mean), and the alias is a problem when a split word picks the target or when an unknown letter comes before a target letter (the message names the letter, never the word). The lists are split apart because kubectl puts the user's words between them, and words after `--` are left alone. The new test's "only the letter is named" check now looks for the joined value rather than "-xn", which a random temporary folder name could hold. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s letters (#140) kubectl runs an alias as a copy of its command, flags included, so in an alias of logs the user's -f is --follow and `-fn kube-system` sets the namespace. The split used the alias's own name, which got the default letters (-f takes a value) and missed the namespace. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 25, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Closes #140. Target: 1.3.0.
What changes
1. kuberc aliases with a short flag group. Before, an alias whose
prependArgsorappendArgsheld a group such as-itnprod,-itn prod,-iAor-is <url>set the target without cloudpin noticing, becausesetsTargetread only the first letter of each word. Now each list is split with #133'ssplitShortGroups, using the letters of the alias's command, so-fand-pin an alias oflogstake no value. The two lists are split separately because kubectl puts the user's words between them. If an unknown letter comes before a target letter, the alias is reported as "can't tell", and the message names the letter but never the word.2. A value that looks like a flag. pflag gives a value letter at the end of its word the next word whole, whatever it holds. So in
kubectl logs pod -c -n xthe container is-nand x is not the namespace.splitShortGroupsnow also reads lone value letters and joins a value taken from the next word to its flag (-c=-n). That wayflag()andallNamespacescan't mistake the value for a flag, and-c --no longer ends the flags. The global long flags inVALUE_FLAGSget the same treatment (--namespace -nbecomes--namespace=-n).3. User flags after an alias. kubectl runs an alias as a copy of its command, so the user's own short flags follow that command's letters. For example,
kubectl <alias of logs> -fn kube-system podis now checked against kube-system.Sources: pflag
flag.go(parseSingleShortArg,parseLongArg,parseArgs), kubernetes.io/docs/reference/kubectl/kuberc/, and kubectlpkg/kuberc/kuberc.go(applyAliases).Tests
All new tests are in
test/kubernetes-kuberc-groups.test.ts: 25 tests, including wrong-pin controls throughguard. They were committed failing first: 15 of the 25 fail on main. Typecheck passes. Full suite: 51 files, 1292 passed, 8 skipped.As a mutation control, I went back to reading alias arguments without the split, and separately dropped the
=join for short values. Each mutation makes 7 tests fail, and the file was restored afterwards.Left open
--container -n x). kubectl has too many to list them all.prependArgsending in a value letter (["-c"]) takes the user's first word. Handling that would mean expanding the alias fully. It's rare, and the mistake only matters when the user also passes-n.appendArgsthat land after a user's--are still scanned. This errs on the side of stopping the command.🤖 Generated with Claude Code