Skip to content

Error on bare group commands with explicit flags#313

Merged
jeremy merged 1 commit intomainfrom
bc-9679134981
Mar 16, 2026
Merged

Error on bare group commands with explicit flags#313
jeremy merged 1 commit intomainfrom
bc-9679134981

Conversation

@jeremy
Copy link
Copy Markdown
Member

@jeremy jeremy commented Mar 16, 2026

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 error
  • Root cause: Cobra returns nil for non-runnable commands, consuming flags but doing nothing with them
  • The help function now detects explicit local flags on bare group commands and suppresses output; Execute() converts 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 renders help regardless of other flags

Test plan

  • TestBareGroupWithFlagsSuppressesHelp — cards --in, cards --project, messages --in all suppress help and are detected
  • TestBareGroupWithoutFlagsShowsHelp — bare cards still renders help normally
  • TestBareGroupWithFlagsAndHelpShowsHelpcards --in X --help renders help (explicit --help wins)
  • All existing help tests pass (JSON help, parent-scoped flags, aliases, etc.)
  • 290 e2e tests pass
  • check-bare-groups.sh passes — groups remain non-runnable in source

Summary 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 --help still shows help.

  • Bug Fixes
    • Suppress help for bare group commands when local flags are set; Execute() emits a usage error and non-zero exit, and suppression runs before --agent/--json handling to avoid mixed output.
    • Explicit --help always renders help, even with other flags.
    • Groups remain non-runnable; PersistentPreRunE does not run for them.

Written for commit d43dafd. Summary will update on new commits.

@jeremy jeremy requested a review from a team as a code owner March 16, 2026 01:58
Copilot AI review requested due to automatic review settings March 16, 2026 01:58
@github-actions github-actions bot added tests Tests (unit and e2e) bug Something isn't working labels Mar 16, 2026
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 (when ExecuteC() returns nil) and convert it into an ErrUsageHint error.
  • Add help-layer tests for suppression vs. normal help behavior (and explicit --help winning).

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.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@github-actions github-actions bot added the breaking Breaking change label Mar 16, 2026
@github-actions
Copy link
Copy Markdown

⚠️ Potential breaking changes detected:

  • The change introduces an error condition when a bare group command is used with explicit flags (e.g., 'command-group --flag value'). Previously, this might have resulted in suppressed help output, but now it produces a usage error. This alters behavior for scripts or users relying on the previous handling of such cases, potentially breaking compatibility.

Review carefully before merging. Consider a major version bump.

@jeremy jeremy merged commit 4501804 into main Mar 16, 2026
25 checks passed
@jeremy jeremy deleted the bc-9679134981 branch March 16, 2026 04:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking Breaking change bug Something isn't working tests Tests (unit and e2e)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants