Skip to content

refactor: collapse the no-arg command preamble into parsePlain#90

Merged
andyrewlee merged 1 commit into
mainfrom
refactor/cmd-parseplain
Jun 21, 2026
Merged

refactor: collapse the no-arg command preamble into parsePlain#90
andyrewlee merged 1 commit into
mainfrom
refactor/cmd-parseplain

Conversation

@andyrewlee

Copy link
Copy Markdown
Owner

What

The 11 read/no-arg commands — abort, bottom, continue, fold, guide, log, repair, status, top, undo, validate — each opened with the identical 8-line preamble:

var asJSON bool
fs := newFlagSet("X", &asJSON)
if err := parseFlagSet(fs, args); err != nil { return err }
if err := rejectArgs("X", fs.Args()); err != nil { return err }

Extracted into parsePlain(command, args) (bool, error) in cmd/util.go. Each call site is now 4 lines, and the "takes no positionals, only --json" contract has a single definition.

Why it's safe

Pure mechanical extraction — no behaviour change. The flag-bearing commands (create, modify, restack, sync, …) are untouched; only the commands whose sole flag is --json and that take no positionals were converted.

make ci green — stdlib-only, lint 0 issues, race + e2e, coverage 86.4%. Net −28 lines.

The 11 read/no-arg commands (abort, bottom, continue, fold, guide, log,
repair, status, top, undo, validate) each repeated the same
newFlagSet -> parseFlagSet -> rejectArgs preamble. Extract it into a
parsePlain(command, args) (bool, error) helper so the "takes no
positionals, only --json" contract has a single home. No behaviour change.
@andyrewlee andyrewlee merged commit 3af5224 into main Jun 21, 2026
4 checks passed
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