Context
cmd/ccsession/main.go (548 lines) repeats the same wiring blocks per backend and per subcommand; each new backend or id-taking subcommand adds another copy.
Current state
applySource (cmd/ccsession/main.go:227-263): four near-identical "conflict check → assign name" blocks for all/opencode/grok/codex.
parseGlobalFlags (main.go:277-303): four identical bool-sugar blocks for --all/--opencode/--grok/--codex.
cmdResumeSpec and cmdResume (main.go:379-436): structurally identical "one --locator flag, exactly one positional id" scaffolding.
(Line numbers as of e5bc967 — re-locate with grep -n if drifted.)
Task
- Replace the shorthand blocks with a table:
var sourceShorthands = map[string]string{
"--all": "all", "--opencode": "opencode", "--grok": "grok", "--codex": "codex",
}
and one loop that performs the conflict check ("cannot combine --X with --source/--Y") with the same error strings as today. Grep main_test.go for the exact expected messages before touching them.
- Extract the shared subcommand scaffolding:
func runIDCommand(name string, args []string, fn func(id, locator string) error) error
and reimplement cmdResumeSpec/cmdResume (and cmdPreview's overlapping parts if it fits naturally — don't force it) on top of it.
- Behavior must be byte-identical, including usage/help text and error messages.
cmd/ccsession/main_test.go already covers much of this; extend it for any conflict combination not yet asserted.
Acceptance criteria
- Adding a hypothetical new backend shorthand requires touching one table, not two function bodies.
- All existing tests pass unmodified except where they gain coverage;
go vet, golangci-lint run, gofmt -l . clean.
Context
cmd/ccsession/main.go(548 lines) repeats the same wiring blocks per backend and per subcommand; each new backend or id-taking subcommand adds another copy.Current state
applySource(cmd/ccsession/main.go:227-263): four near-identical "conflict check → assign name" blocks forall/opencode/grok/codex.parseGlobalFlags(main.go:277-303): four identical bool-sugar blocks for--all/--opencode/--grok/--codex.cmdResumeSpecandcmdResume(main.go:379-436): structurally identical "one--locatorflag, exactly one positional id" scaffolding.(Line numbers as of e5bc967 — re-locate with
grep -nif drifted.)Task
main_test.gofor the exact expected messages before touching them.cmdResumeSpec/cmdResume(andcmdPreview's overlapping parts if it fits naturally — don't force it) on top of it.cmd/ccsession/main_test.goalready covers much of this; extend it for any conflict combination not yet asserted.Acceptance criteria
go vet,golangci-lint run,gofmt -l .clean.