Skip to content

fix(cli): surface clap's --help instead of erroring on native subcommands#1380

Draft
jd wants to merge 1 commit intodevs/jd/worktree-rust-port/extract-reusable-terminal-ui-primitives-mergify--bbdbce1efrom
devs/jd/worktree-rust-port/surface-clap-s-help-instead-erroring-native--2922aa2d
Draft

fix(cli): surface clap's --help instead of erroring on native subcommands#1380
jd wants to merge 1 commit intodevs/jd/worktree-rust-port/extract-reusable-terminal-ui-primitives-mergify--bbdbce1efrom
devs/jd/worktree-rust-port/surface-clap-s-help-instead-erroring-native--2922aa2d

Conversation

@jd
Copy link
Copy Markdown
Member

@jd jd commented May 6, 2026

Reported by user: mergify queue status --help rejected the
flag with error: unexpected argument '--help' found. Root
cause: CliRoot had disable_help_flag = true, so clap's
auto-generated --help machinery wasn't wired up — and our
detect_native then surfaced the resulting parser error
(because looks_native matched) instead of falling through.

Two changes:

  1. Drop disable_help_flag = true from CliRoot. clap now
    auto-recognizes -h / --help at every level and
    generates its standard help blurb listing flags + subcommands.

  2. detect_native catches the special help-error kinds
    (DisplayHelp and
    DisplayHelpOnMissingArgumentOrSubcommand) explicitly and
    calls err.exit() regardless of the looks_native
    heuristic. err.exit() prints help to stdout and calls
    process::exit(0). The previous flow also called
    err.exit() on parser errors when looks_native, but it
    only fired when the argv contained a (group, subcommand) pair
    — root-level mergify --help had no such pair so it would
    have leaked to the Python shim.

Verified locally:

  • mergify --help lists the three native top-level groups
    (config / ci / queue).
  • mergify queue --help lists the native queue subcommands
    (pause / unpause / status).
  • mergify queue status --help shows --branch / --json
    / --token / --api-url / --repository with their
    doc-strings.

Known follow-up: mergify queue --help doesn't list show
because it's still shimmed (no clap variant). Fixable by
registering opaque clap stubs for shimmed commands; deferred to
the PR that ports queue show.

Co-Authored-By: Claude Opus 4.7 (1M context) noreply@anthropic.com

Depends-On: #1379

…ands

Reported by user: ``mergify queue status --help`` rejected the
flag with ``error: unexpected argument '--help' found``. Root
cause: ``CliRoot`` had ``disable_help_flag = true``, so clap's
auto-generated ``--help`` machinery wasn't wired up — and our
``detect_native`` then surfaced the resulting parser error
(because ``looks_native`` matched) instead of falling through.

Two changes:

1. Drop ``disable_help_flag = true`` from ``CliRoot``. clap now
   auto-recognizes ``-h`` / ``--help`` at every level and
   generates its standard help blurb listing flags + subcommands.

2. ``detect_native`` catches the special help-error kinds
   (``DisplayHelp`` and
   ``DisplayHelpOnMissingArgumentOrSubcommand``) explicitly and
   calls ``err.exit()`` regardless of the ``looks_native``
   heuristic. ``err.exit()`` prints help to stdout and calls
   ``process::exit(0)``. The previous flow also called
   ``err.exit()`` on parser errors when ``looks_native``, but it
   only fired when the argv contained a (group, subcommand) pair
   — root-level ``mergify --help`` had no such pair so it would
   have leaked to the Python shim.

Verified locally:

- ``mergify --help`` lists the three native top-level groups
  (``config`` / ``ci`` / ``queue``).
- ``mergify queue --help`` lists the native queue subcommands
  (``pause`` / ``unpause`` / ``status``).
- ``mergify queue status --help`` shows ``--branch`` / ``--json``
  / ``--token`` / ``--api-url`` / ``--repository`` with their
  doc-strings.

Known follow-up: ``mergify queue --help`` doesn't list ``show``
because it's still shimmed (no clap variant). Fixable by
registering opaque clap stubs for shimmed commands; deferred to
the PR that ports ``queue show``.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Change-Id: I2922aa2d83af6c99cb551f2a95bf5a4959832375
@jd
Copy link
Copy Markdown
Member Author

jd commented May 6, 2026

This pull request is part of a Mergify stack:

# Pull Request Link
1 feat(rust): port queue pause and unpause to native Rust #1352
2 feat(rust): port ci git-refs and ci queue-info to native Rust #1353
3 feat(rust): port queue status to native Rust #1359
4 test: derive native queue commands from the binary, not a hardcoded list #1366
5 feat(rust): extract reusable terminal-UI primitives into mergify-tui #1379
6 fix(cli): surface clap's --help instead of erroring on native subcommands #1380 👈

@mergify
Copy link
Copy Markdown
Contributor

mergify Bot commented May 6, 2026

Merge Protections

Your pull request matches the following merge protections and will not be merged until they are valid.

🔴 ⛓️ Depends-On Requirements

Waiting for

This rule is failing.

Requirement based on the presence of Depends-On in the body of the pull request

🔴 🤖 Continuous Integration

Waiting for

  • check-success=ci-gate
This rule is failing.
  • all of:
    • check-success=ci-gate

🔴 👀 Review Requirements

Waiting for

  • #approved-reviews-by>=2
This rule is failing.
  • any of:
    • #approved-reviews-by>=2
    • author = dependabot[bot]
    • author = mergify-ci-bot
    • author = renovate[bot]

🟢 Enforce conventional commit

Wonderful, this rule succeeded.

Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/

  • title ~= ^(fix|feat|docs|style|refactor|perf|test|build|ci|chore|revert|ui)(?:\(.+\))?:

🟢 🔎 Reviews

Wonderful, this rule succeeded.
  • #changes-requested-reviews-by = 0
  • #review-requested = 0
  • #review-threads-unresolved = 0

🟢 📕 PR description

Wonderful, this rule succeeded.
  • body ~= (?ms:.{48,})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant