fix: handle --help flag in exec command for non-shell scripts#409
Conversation
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>
There was a problem hiding this comment.
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/--helpflag processing to theExecstruct - Implemented a new
help()method that usesparse_partialto 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.
| 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)?; | ||
|
|
There was a problem hiding this comment.
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); }
| 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)?; |
Codecov Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
## [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)
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 [@​jdx](https://github.com/jdx) in [#​410](jdx/usage#410) ##### 🐛 Bug Fixes - handle --help flag in exec command for non-shell scripts by [@​jdx](https://github.com/jdx) in [#​409](jdx/usage#409) ##### 🧪 Testing - add non-shell script tests by [@​muzimuzhi](https://github.com/muzimuzhi) in [#​406](jdx/usage#406) ##### 📦️ Dependency Updates - lock file maintenance by [@​renovate\[bot\]](https://github.com/renovate\[bot]) in [#​403](jdx/usage#403) - lock file maintenance by [@​renovate\[bot\]](https://github.com/renovate\[bot]) in [#​407](jdx/usage#407) - lock file maintenance by [@​renovate\[bot\]](https://github.com/renovate\[bot]) in [#​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-->
Summary
execcommand handle--helpthe same way shell commands do by disabling clap's built-in help flag and manually intercepting-h/--helpChanges
disable_help_flag = trueto the Exec struct's clap attribute-hand--helpflag fields to capture help requestsparse_partialandrender_helpTest plan
test_exec_helptest that verifiesusage exec python3 <script> --helpshows the script's help🤖 Generated with Claude Code
Note
Makes
usage execintercept-h/--helpand render script help consistently with shell subcommands.execand adds explicit-h/--helpflags; handles help viaparse_partial+render_helpbefore full parsecli/assets/fig.ts, manpage (cli/assets/usage.1), KDL spec, docs (docs/cli/reference/*.md,commands.json)test_exec_helpand a Python example scriptexamples/test-exec-help.pyto validate help outputWritten by Cursor Bugbot for commit e82d373. This will update automatically on new commits. Configure here.