Fix section subcommand help when a global flag precedes the section (MIR-1309)#908
Conversation
`miren -C <cluster> auth help` (and `miren -C <cluster> auth`) printed top-level help instead of the auth section's subcommands. The mflags interspersed-flag resolver rejected the section match because the section's empty flagset doesn't declare -C; that fix lands in mflags. On this side, sections now tolerate unknown flags so the no-help form parses and renders its subcommands via ErrShowHelp instead of erroring. - cli/commands/help.go: Section flagsets set AllowUnknownFlags(true). - cli/commands/section_help_test.go: regression test via RegisterAll. - go.mod: bump miren.dev/mflags to the resolver fix. Fixes MIR-1309.
📝 WalkthroughWalkthroughSection help now uses a dedicated flag set that allows unknown flags before a section name. The mflags dependency is updated, and tests cover multiple global-flag and help argument combinations while verifying that auth sub-command help is rendered. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
cli/commands/section_help_test.go (1)
57-79: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick winPipe read happens only after
Executereturns — risk of deadlock if output exceeds pipe buffer.
os.Pipe()has a fixed OS buffer (~64KB on Linux). Since nothing reads fromruntil afterExecutefinishes andwis closed, a subcommand writing more than the buffer size would block forever on write. Fine for today's small help output, but fragile if this helper is reused for larger outputs. Reading concurrently in a goroutine (or draining incrementally) removes the risk.♻️ Suggested fix using concurrent drain
d := mflags.NewDispatcher("miren") RegisterAll(d) old := os.Stdout r, w, _ := os.Pipe() os.Stdout = w + outCh := make(chan string, 1) + go func() { + var buf bytes.Buffer + io.Copy(&buf, r) + outCh <- buf.String() + }() + err := d.Execute(args) w.Close() os.Stdout = old if err != nil { t.Fatalf("Execute(%v) returned error: %v", args, err) } - var buf bytes.Buffer - io.Copy(&buf, r) - return buf.String() + return <-outCh }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@cli/commands/section_help_test.go` around lines 57 - 79, Update captureDispatch to drain the pipe concurrently while d.Execute(args) runs, rather than reading from r only after execution completes. Start a goroutine that copies from r into a buffer, then execute, close w, wait for the reader, restore os.Stdout safely, and preserve the existing error handling.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@cli/commands/section_help_test.go`:
- Around line 57-79: Update captureDispatch to drain the pipe concurrently while
d.Execute(args) runs, rather than reading from r only after execution completes.
Start a goroutine that copies from r into a buffer, then execute, close w, wait
for the reader, restore os.Stdout safely, and preserve the existing error
handling.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 818598d9-6da0-4568-9e52-849046fd4e16
⛔ Files ignored due to path filters (1)
go.sumis excluded by!**/*.sum
📒 Files selected for processing (3)
cli/commands/help.gocli/commands/section_help_test.gogo.mod
Problem
MIR-1309 was filed as "
miren help authrefuses to show the subcommands," butthat form works. The real defect: a value-taking global flag before a section
name breaks subcommand help.
auth(andenv,sandbox,config, …) is aSectionwith an emptyflagset. The mflags interspersed-flag resolver correctly guessed
-Cconsumedprod, matched theauthsection, then rejected the match because-Cisn'tdeclared in the section's flagset — falling back to top-level help.
Fix
Two parts:
rejects a matched command path just because a pre-command flag is unknown to
it. This PR bumps the pin to that commit.
AllowUnknownFlags(true), so theno-help form (
miren -C prod auth) parses the leftover global flag andrenders subcommands via
ErrShowHelpinstead of erroring.Tests
cli/commands/section_help_test.go— new regression test built viaRegisterAll, coveringmiren [-C prod] auth [help|--help].subcommands;
-C prod app liststill receives the cluster and-C prod auth generatestill runs the real command.Fixes MIR-1309.