Error on bare group commands with explicit flags#313
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c3dc579d7f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
Pull request overview
This PR improves CLI UX by turning “bare group command + explicit flags” invocations (e.g., basecamp cards --in myproject) from a silent help+exit-0 outcome into a proper “subcommand required” usage error with a non-zero exit code.
Changes:
- Suppress help rendering for non-runnable group commands when local flags were explicitly set (so Cobra doesn’t print help and still return
nil). - In
cli.Execute(), detect this “bare group with flags” case (whenExecuteC()returnsnil) and convert it into anErrUsageHinterror. - Add help-layer tests for suppression vs. normal help behavior (and explicit
--helpwinning).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| internal/cli/root.go | Converts Cobra’s nil result for bare non-runnable groups-with-flags into a non-zero usage error. |
| internal/cli/help.go | Adds detection logic (isBareGroupWithFlags) and suppresses help output for the problematic invocation style. |
| internal/cli/help_test.go | Adds regression tests for bare group behavior with/without flags and with explicit --help. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
1 issue found across 3 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="internal/cli/help.go">
<violation number="1" location="internal/cli/help.go:35">
P2: The `isBareGroupWithFlags` check is positioned after the `--agent`/`--json` machine-help branches. For a bare group invocation like `cards --in myproject --json`, the `--json` branch will emit structured help output and return, then `Execute()` will detect `isBareGroupWithFlags` and produce a usage error — resulting in mixed machine output (help payload followed by error). Move the `isBareGroupWithFlags` check before the machine-help emission branches so that suppression takes effect regardless of output format flags.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
`basecamp cards --in myproject` silently showed help and exited 0 because Cobra treats non-runnable commands as help-only. Now the help function detects explicit local flags (--in, --project, etc.) on bare group invocations and suppresses output so Execute() can convert to a "subcommand required" usage error with non-zero exit. Groups stay non-runnable (no RunE set), PersistentPreRunE never fires for them, and explicit --help always wins regardless of other flags. The suppression check runs before --agent/--json branches to prevent mixed machine output.
Review carefully before merging. Consider a major version bump. |
Summary
basecamp cards --in myproject(and similar bare group invocations with explicit flags) silently showed help text and exited 0 — the user expected an action or at least a clear errorExecute()converts to a "subcommand required" usage error with non-zero exitRunEset),PersistentPreRunEnever fires for them, and explicit--helpalways renders help regardless of other flagsTest plan
TestBareGroupWithFlagsSuppressesHelp— cards --in, cards --project, messages --in all suppress help and are detectedTestBareGroupWithoutFlagsShowsHelp— barecardsstill renders help normallyTestBareGroupWithFlagsAndHelpShowsHelp—cards --in X --helprenders help (explicit --help wins)check-bare-groups.shpasses — groups remain non-runnable in sourceSummary by cubic
Fixes bare group commands with explicit flags (e.g.,
basecamp cards --in myproject) that previously printed help and exited 0. Now they return a clear “subcommand required” usage error and exit non-zero; explicit--helpstill shows help.Execute()emits a usage error and non-zero exit, and suppression runs before--agent/--jsonhandling to avoid mixed output.--helpalways renders help, even with other flags.PersistentPreRunEdoes not run for them.Written for commit d43dafd. Summary will update on new commits.