Flag parsing is hand-rolled in 39 command bodies #96

closed cmc opened this on 2026-09-03 05:12 UTC · cli control · milestone v1.10.0

Discussion

cmc 2026-09-03 05:12 UTC

for i := 0; i < len(args); i++ appears in 39 command bodies and "requires a value" 42 times. Each loop decides on its own whether an unknown --flag is an error (read.go:231), a positional (issue.go:153) or silently swallowed (mr.go:794). mr review --approve --bogus reports repository --bogus as not found instead of a usage error. Usage strings and parsers are written separately and can disagree.

Remedy: one parseFlags(args, spec) (pos, vals, code) in control.go, with Usage derived from the spec. This also unlocks table-driven unit tests for command parsing.

closed by commit 94884a2232 by cmc: control: one flag parser for every command

2026-09-04 01:05 UTC