Skip to content

refactor(spored): convert hand-rolled CLI to cobra (#40) - #43

Merged
scttfrdmn merged 1 commit into
mainfrom
chore/40-spored-cobra
Jun 3, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
chore/40-spored-cobra

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Final piece of the spawn#40 suite-wide flag normalization (spawn #42, truffle #17, lagotto #17 already merged).

What

spored parsed args with a hand-rolled switch os.Args[1] + manual os.Args[2:] slicing — sharing no flag infrastructure with the other CLIs. Converted to a cobra command tree for consistent parsing, structured help, and the same conventions as spawn/truffle/lagotto.

Contracts preserved exactly

spawn shells out to spored and the user-data bootstrap depends on it, so every contract is unchanged — verified against the built binary:

Invocation Behavior
spored (no args) lifecycle daemon (extracted to runDaemon(); systemd ExecStart)
spored status --check-complete exit codes 0/1/2/3 (the #26 contract)
spored config get/set/list unchanged
spored reload unchanged
spored complete --status/--message/--file now via cobra flags
spored run-queue <file>, run-pipeline-stage unchanged
spored version kept as explicit subcommand (cobra --version alone would break scripts/install-spored.sh); --version works too

Handlers now return errors instead of calling os.Exit directly — except the --check-complete exit-code path, which must os.Exit by contract. Removed the hand-written printHelp and manual flag loops (cobra provides both).

Test

TestCLIContract locks the subcommand names, status --check-complete, the complete flags, config get/set/list, and the version subcommand, so the external surface can't silently regress. TestCheckCompleteCode unchanged. go build ./..., go vet, go test ./cmd/... green; manually verified daemon mode, check-complete exit 2, config, complete, version.

Tracking: spawn#40.

spored parsed args with a hand-rolled 'switch os.Args[1]' and manual
os.Args[2:] slicing, sharing no flag infrastructure with spawn/truffle/
lagotto. Convert to a cobra command tree so it follows the same
conventions, with structured help and consistent flag parsing.

Every external contract is preserved exactly (spawn shells out to these
and the user-data bootstrap depends on them):
- bare 'spored' → lifecycle daemon (extracted to runDaemon())
- 'spored status --check-complete' → exit codes 0/1/2/3 (unchanged)
- 'spored config get|set|list', 'spored reload'
- 'spored complete --status/--message/--file' (now via cobra flags)
- 'spored run-queue <file>', 'spored run-pipeline-stage'
- 'spored version' → kept as an explicit subcommand (cobra's --version
  flag alone would break scripts/install-spored.sh); --version also works

Handlers now return errors instead of calling os.Exit directly (except
the --check-complete exit-code path, which must os.Exit by contract).
Removed the hand-written printHelp and manual flag loops; cobra provides
help and parsing.

Adds TestCLIContract locking the subcommand names, status --check-complete,
complete flags, config get/set/list, and the version subcommand, so the
contracts can't silently regress. Existing TestCheckCompleteCode unchanged.

Completes the spawn#40 suite-wide flag normalization (spawn, truffle,
lagotto, spored).
@codecov

codecov Bot commented Jun 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 51.03448% with 71 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/spored/main.go 51.03% 64 Missing and 7 partials ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit bd23732 into main Jun 3, 2026
3 checks passed
@scttfrdmn
scttfrdmn deleted the chore/40-spored-cobra branch June 3, 2026 17:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant