Skip to content

fix(launch): accept the spore name as either the positional or --name - #692

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/499-launch-name
Oct 4, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/499-launch-name

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

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:

$ spawn launch verify-667-668 --instance-type t4g.small ... --name verify-667-668
accepts 1 arg(s), received 0

I had written --name, exactly as the flag's own help says is required.

The contradiction, confirmed

spawn launch --help says three things that cannot all be true:

Examples:
  spawn launch --instance-type m7i.large --region us-east-1   <-- no name at all
Usage:
  spawn launch <name> [flags]                                 <-- positional required
Flags:
  --name string   Name your spore, required (...)             <-- flag required

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

runLaunch already read both forms — cmd/launch_single.go:60 does if len(args) > 0 && name == "" { name = args[0] }, so --name wins and the positional fills in. The only obstacle was cobra.ExactArgs(1), which cannot express the rule: it sees the positional count and nothing else, so --name alone is indistinguishable from passing nothing.

launchNameArgs replaces it and names what is actually wrong in each case:

invocation before after
launch my-spore works works
launch --name my-spore accepts 1 arg(s), received 0 works
launch (the example) accepts 1 arg(s), received 0 a spore name is required: pass it positionally (spawn launch my-spore) or with --name my-spore
launch aaa --name bbb silently used bbb conflicting names: positional "aaa" and --name "bbb" — pass one

The 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 --name help now states that either form works, and docs-gen/launch.md is regenerated.

Still outstanding, in another repo

The "Direct with flags" example that omits the name entirely lives in spore-host/libs (i18n key spawn.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:

if strings.Contains(f.Usage, "required") && !strings.Contains(f.Usage, "or") { ... }

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 -l empty, 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.

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

codecov Bot commented Oct 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant