Skip to content

fix: handle --help flag in exec command for non-shell scripts#409

Merged
jdx merged 2 commits intomainfrom
fix-exec-help-flag
Dec 30, 2025
Merged

fix: handle --help flag in exec command for non-shell scripts#409
jdx merged 2 commits intomainfrom
fix-exec-help-flag

Conversation

@jdx
Copy link
Owner

@jdx jdx commented Dec 30, 2025

Summary

Changes

  • Added disable_help_flag = true to the Exec struct's clap attribute
  • Added -h and --help flag fields to capture help requests
  • Added help handling before parsing that renders the script's help using parse_partial and render_help
  • Added test with a Python test script to verify the fix

Test plan

  • Added test_exec_help test that verifies usage exec python3 <script> --help shows the script's help
  • All existing tests pass

🤖 Generated with Claude Code


Note

Makes usage exec intercept -h/--help and render script help consistently with shell subcommands.

  • Disables clap’s built-in help for exec and adds explicit -h/--help flags; handles help via parse_partial + render_help before full parse
  • Updates generated artifacts: cli/assets/fig.ts, manpage (cli/assets/usage.1), KDL spec, docs (docs/cli/reference/*.md, commands.json)
  • Adds test_exec_help and a Python example script examples/test-exec-help.py to validate help output

Written by Cursor Bugbot for commit e82d373. This will update automatically on new commits. Configure here.

jdx and others added 2 commits December 30, 2025 10:18
Previously, `usage exec <cmd> <script> --help` would show help for the
`usage exec` command itself instead of the script's help. This was because
clap intercepted the --help flag before the exec command could handle it.

This fix makes the exec command handle help the same way the shell commands
do by:
- Adding `disable_help_flag = true` to the clap attribute
- Manually capturing `-h` and `--help` flags
- Rendering the script's help using the parsed spec

Fixes #405

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings December 30, 2025 18:19
Copy link
Contributor

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 fixes issue #405 by enabling the exec command to handle --help flags for non-shell scripts, matching the behavior of shell commands. Previously, --help was consumed by clap's built-in help system instead of being passed to the script.

Key changes:

  • Disabled clap's default help flag handling and added manual -h/--help flag processing to the Exec struct
  • Implemented a new help() method that uses parse_partial to render the script's help documentation
  • Added test coverage with a Python script example to verify the fix works for non-shell scripts

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
cli/src/cli/exec.rs Added manual help flag handling and help rendering method
cli/tests/examples.rs Added test verifying --help works with Python scripts
examples/test-exec-help.py Created Python test script demonstrating help functionality
cli/usage.usage.kdl Updated spec to include -h and --help flags
docs/cli/reference/exec.md Updated documentation to reflect new flags
docs/cli/reference/index.md Updated command signature
docs/cli/reference/commands.json Updated JSON spec with flag definitions
cli/assets/usage.1 Updated man page with new options
cli/assets/fig.ts Updated Fig completion spec with new options

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +54 to 62
if self.h {
return self.help(&spec, &args, false);
}
if self.help {
return self.help(&spec, &args, true);
}

let parsed = usage::parse::parse(&spec, &args)?;

Copy link

Copilot AI Dec 30, 2025

Choose a reason for hiding this comment

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

The two separate if statements checking self.h and self.help can be combined into a single conditional since they perform the same action with only the long parameter differing. Consider using: if self.h || self.help { return self.help(&spec, &args, self.help); }

Suggested change
if self.h {
return self.help(&spec, &args, false);
}
if self.help {
return self.help(&spec, &args, true);
}
let parsed = usage::parse::parse(&spec, &args)?;
if self.h || self.help {
return self.help(&spec, &args, self.help);
}
let parsed = usage::parse::parse(&spec, &args)?;

Copilot uses AI. Check for mistakes.
@codecov
Copy link

codecov bot commented Dec 30, 2025

Codecov Report

❌ Patch coverage is 19.04762% with 17 lines in your changes missing coverage. Please review.
✅ Project coverage is 57.32%. Comparing base (deff9b6) to head (e82d373).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
cli/src/cli/exec.rs 19.04% 11 Missing and 6 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #409      +/-   ##
==========================================
+ Coverage   57.22%   57.32%   +0.10%     
==========================================
  Files          47       47              
  Lines        5543     5561      +18     
  Branches     5543     5561      +18     
==========================================
+ Hits         3172     3188      +16     
+ Misses       1337     1316      -21     
- Partials     1034     1057      +23     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jdx jdx merged commit 8723415 into main Dec 30, 2025
10 of 11 checks passed
@jdx jdx deleted the fix-exec-help-flag branch December 30, 2025 18:29
jdx pushed a commit that referenced this pull request Dec 31, 2025
## [2.11.0](https://github.com/jdx/usage/compare/v2.10.0..v2.11.0) -
2025-12-31

### 🚀 Features

- add default_subcommand and restart_token for naked task completions by
[@jdx](https://github.com/jdx) in
[#410](#410)

### 🐛 Bug Fixes

- handle --help flag in exec command for non-shell scripts by
[@jdx](https://github.com/jdx) in
[#409](#409)

### 🧪 Testing

- add non-shell script tests by
[@muzimuzhi](https://github.com/muzimuzhi) in
[#406](#406)

### 📦️ Dependency Updates

- lock file maintenance by
[@renovate[bot]](https://github.com/renovate[bot]) in
[#403](#403)
- lock file maintenance by
[@renovate[bot]](https://github.com/renovate[bot]) in
[#407](#407)
- lock file maintenance by
[@renovate[bot]](https://github.com/renovate[bot]) in
[#408](#408)
tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Jan 9, 2026
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [usage](https://github.com/jdx/usage) | minor | `2.10.0` → `2.11.0` |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>jdx/usage (usage)</summary>

### [`v2.11.0`](https://github.com/jdx/usage/blob/HEAD/CHANGELOG.md#2110---2025-12-31)

[Compare Source](jdx/usage@v2.10.0...v2.11.0)

##### 🚀 Features

- add default\_subcommand and restart\_token for naked task completions by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;410](jdx/usage#410)

##### 🐛 Bug Fixes

- handle --help flag in exec command for non-shell scripts by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;409](jdx/usage#409)

##### 🧪 Testing

- add non-shell script tests by [@&#8203;muzimuzhi](https://github.com/muzimuzhi) in [#&#8203;406](jdx/usage#406)

##### 📦️ Dependency Updates

- lock file maintenance by [@&#8203;renovate\[bot\]](https://github.com/renovate\[bot]) in [#&#8203;403](jdx/usage#403)
- lock file maintenance by [@&#8203;renovate\[bot\]](https://github.com/renovate\[bot]) in [#&#8203;407](jdx/usage#407)
- lock file maintenance by [@&#8203;renovate\[bot\]](https://github.com/renovate\[bot]) in [#&#8203;408](jdx/usage#408)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0Mi42OS4yIiwidXBkYXRlZEluVmVyIjoiNDIuNjkuMiIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiUmVub3ZhdGUgQm90IiwiYXV0b21hdGlvbjpib3QtYXV0aG9yZWQiLCJkZXBlbmRlbmN5LXR5cGU6Om1pbm9yIl19-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot print help of non-shell scripts

2 participants