Skip to content

test: pin that --help ahead of a subcommand prints help - #1342

Merged
mbevc1 merged 1 commit into
mainfrom
20261106_fix_flags
Nov 6, 2026
Merged

mbevc1 merged 1 commit into
mainfrom
20261106_fix_flags

Conversation

@mbevc1

@mbevc1 mbevc1 commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

With TraverseChildren, each command parses its own flags while cobra walks down to the subcommand. --help works ahead of a subcommand only because cobra adds the flag at execute time, so a parent has not declared it yet and stops with "help requested". If a parent declared --help up front, it would consume the flag and hand the run to the subcommand: kosli --help attest generic would run the attestation instead of printing help.

Checklist

@github-actions github-actions Bot added the go Pull requests that update go code label Nov 6, 2026
With TraverseChildren, each command parses its own flags while cobra
walks down to the subcommand. --help works ahead of a subcommand only
because cobra adds the flag at execute time, so a parent has not
declared it yet and stops with "help requested". If a parent declared
--help up front, it would consume the flag and hand the run to the
subcommand: `kosli --help attest generic` would run the attestation
instead of printing help.

Nothing covered this, and the obvious way to restyle --help after the
pflag 1.1.0 bump (declaring it before the flag wrapping) breaks it.
@github-actions github-actions Bot added the test label Nov 6, 2026
@mbevc1
mbevc1 force-pushed the 20261106_fix_flags branch from 603a012 to fa1606b Compare November 6, 2026 09:42
@mbevc1
mbevc1 enabled auto-merge (squash) November 6, 2026 09:42
@claude

claude Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @mbevc1's task in 1m 9s —— View job


Follow-up review complete

Previous findings: none. This PR has a single commit (fa1606bb), and there is no prior Claude review on it containing findings to re-evaluate — the only existing comment is this one's own placeholder from this run.

New commits reviewed: cmd/kosli/root_test.go (+14), adding TestHelpBeforeSubcommandShowsHelp, which pins that --help placed before a subcommand (--help version, --debug --help version, archive --help flow) prints help rather than running the subcommand, guarding against a future regression if TraverseChildren parsing changes. The test correctly uses the combined output stream from executeCommandC, and the subcommands it exercises (version, archive flow) exist. No bugs, security issues, or regressions found in the changed lines.

Note: I was unable to run go test/go build/go vet/gofmt in this sandbox — all Bash invocations required manual approval that wasn't available. If you'd like me to execute the test suite as part of this review, please update --allowedTools to permit go test/go vet/gofmt invocations.

@mbevc1
mbevc1 merged commit dfd5006 into main Nov 6, 2026
23 checks passed
@mbevc1
mbevc1 deleted the 20261106_fix_flags branch November 6, 2026 09:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

go Pull requests that update go code test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants