Repository navigation
fix(launch): accept the spore name as either the positional or --name - #692
Merged
Merged
Conversation
The name had to be positional, while --name's own help called itself "required" and the "Direct with flags" example omitted the positional entirely. Following either piece of the built-in documentation failed with "accepts 1 arg(s), received 0" — a message that never mentions the name, so it pointed at nothing. runLaunch already read both forms; only cobra.ExactArgs(1) stood in the way, and it cannot express the rule because it sees only the positional count. Either form is now accepted, the help says so, and the three failure cases each name what is wrong: no name, two disagreeing names, or extra positionals. Fixes #499
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This was referenced Oct 4, 2026
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.
Fixes #499. Reproduced verbatim — and I hit this myself earlier today while scripting a verification run, which is how it got pulled forward in the queue:
I had written
--name, exactly as the flag's own help says is required.The contradiction, confirmed
spawn launch --helpsays three things that cannot all be true:And the failure message never mentions the name, so a caller following the documentation gets an error pointing at nothing.
The fix is smaller than it looks
runLaunchalready read both forms —cmd/launch_single.go:60doesif len(args) > 0 && name == "" { name = args[0] }, so--namewins and the positional fills in. The only obstacle wascobra.ExactArgs(1), which cannot express the rule: it sees the positional count and nothing else, so--namealone is indistinguishable from passing nothing.launchNameArgsreplaces it and names what is actually wrong in each case:launch my-sporelaunch --name my-sporeaccepts 1 arg(s), received 0launch(the example)accepts 1 arg(s), received 0a spore name is required: pass it positionally (spawn launch my-spore) or with --name my-sporelaunch aaa --name bbbbbbconflicting names: positional "aaa" and --name "bbb" — pass oneThe conflicting case was previously silent, and I made it an error rather than keeping the precedence: the Name tag, the DNS record and the hostname all come from this value, so quietly picking one of two names the caller typed is not cosmetic.
The
--namehelp now states that either form works, anddocs-gen/launch.mdis regenerated.Still outstanding, in another repo
The "Direct with flags" example that omits the name entirely lives in
spore-host/libs(i18nkeyspawn.launch.long), not here. After this change that example gives a useful error instead of a baffling one, but it is still a documented invocation that cannot work. I'll fix it there — flagging it so this PR isn't mistaken for closing the whole report.A note on one of my own tests
My first version of the help-text assertion was:
It passed immediately — because "spore" contains the substring "or". A test that cannot fail is worse than no test, and it is the same mistake as #684's region-substitution test. It is now a positive assertion (the help must mention the positional form), with the vacuity recorded in a comment so nobody rewrites it the clever way.
Gates
gofmt -lempty,go vet ./...,go test -short ./...,make check-docs, changelog gate. Six-case table test on the arg validator, plus all four invocations exercised against a real built binary.