Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds support for a bracketed header syntax for USAGE directives (e.g., # [USAGE] or #[USAGE]), similar to the syntax used in mise. The implementation maintains backward compatibility with the original #USAGE and //USAGE formats while introducing the new bracketed variants.
Key changes:
- Modified regex patterns to match both original (
#USAGE,//USAGE) and bracketed (# [USAGE],#[USAGE]) syntax variants - Refactored comment extraction logic to use regex captures instead of string prefix stripping
- Added comprehensive test coverage for all syntax variations and edge cases
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| lib/src/spec/mod.rs | Updated regex patterns and extraction logic to support bracketed USAGE syntax; added unit tests for all syntax variants |
| examples/test-usage-double-slash.js | Example demonstrating new bracketed syntax with // comments in JavaScript |
| examples/test-usage-double-slash-old.js | Example showing original //USAGE syntax for comparison |
| examples/test-usage-bracket-no-space.sh | Example demonstrating #[USAGE] syntax without space in shell script |
| examples/test-new-usage-syntax.sh | Example demonstrating # [USAGE] syntax with space in shell script |
| cli/tests/examples.rs | Integration tests verifying new bracketed syntax works correctly in real usage scenarios |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #377 +/- ##
==========================================
+ Coverage 69.94% 70.08% +0.14%
==========================================
Files 45 45
Lines 4379 4383 +4
Branches 4379 4383 +4
==========================================
+ Hits 3063 3072 +9
+ Misses 1016 1011 -5
Partials 300 300 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Could you add a couple of test cases to ensure we dont support |
Sure! |
|
bugbot run |
This MR contains the following updates: | Package | Update | Change | |---|---|---| | [usage](https://github.com/jdx/usage) | minor | `2.6.0` -> `2.8.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.8.0`](https://github.com/jdx/usage/blob/HEAD/CHANGELOG.md#280---2025-11-12) [Compare Source](jdx/usage@v2.7.0...v2.8.0) ##### 🚀 Features - add examples section to markdown and manpage generation by [@​jdx](https://github.com/jdx) in [#​380](jdx/usage#380) - add examples support to spec-level by [@​jdx](https://github.com/jdx) in [#​382](jdx/usage#382) ##### 🐛 Bug Fixes - allow blank comment lines in #USAGE blocks by [@​jdx](https://github.com/jdx) in [#​381](jdx/usage#381) ### [`v2.7.0`](https://github.com/jdx/usage/blob/HEAD/CHANGELOG.md#270---2025-11-11) [Compare Source](jdx/usage@v2.6.0...v2.7.0) ##### 🚀 Features - support bracketed header syntax by [@​okuuva](https://github.com/okuuva) in [#​377](jdx/usage#377) ##### 📚 Documentation - Fix VitePress build error in markdown documentation by [@​jdx](https://github.com/jdx) in [#​378](jdx/usage#378) ##### 🔍 Other Changes - integrate clap-sort to enforce alphabetical subcommand ordering by [@​jdx](https://github.com/jdx) in [#​370](jdx/usage#370) ##### 📦️ Dependency Updates - lock file maintenance by [@​renovate\[bot\]](https://github.com/renovate\[bot]) in [#​372](jdx/usage#372) - update rust crate clap-sort to v1.0.3 by [@​renovate\[bot\]](https://github.com/renovate\[bot]) in [#​373](jdx/usage#373) - update rust crate ctor to v0.6.1 by [@​renovate\[bot\]](https://github.com/renovate\[bot]) in [#​374](jdx/usage#374) - lock file maintenance by [@​renovate\[bot\]](https://github.com/renovate\[bot]) in [#​375](jdx/usage#375) ##### New Contributors - [@​okuuva](https://github.com/okuuva) made their first contribution in [#​377](jdx/usage#377) </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:eyJjcmVhdGVkSW5WZXIiOiI0MS4xNzMuMSIsInVwZGF0ZWRJblZlciI6IjQxLjE3My4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJSZW5vdmF0ZSBCb3QiXX0=-->
Fixes the shebangs in two JavaScript examples added by #377, and add usage tests for them. Note that no `--help` tests were added, due to - #405 <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Adds coverage for non-shell script `// [USAGE]` and legacy `//USAGE` parsing/execution and corrects JS example shebangs. > > - New tests in `cli/tests/examples.rs` execute Node examples via `usage exec node`, asserting parsed flags/args and defaults > - Update `examples/test-usage-double-slash.js` and `...-old.js` shebangs to `#!/usr/bin/env -S usage exec node` and refine comments > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 967b94e. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Adds support for a bracketed header syntax, similar to that in
mise.Note
Add regex-based parsing to support bracketed
[USAGE]headers across#,//, and::(with/without space), with new examples and tests.[USAGE]markers via regex inlib/src/spec/mod.rs(split_script,extract_usage_from_comments).#,//, and::prefixes and both[USAGE]andUSAGEforms; captures content after the marker; stops on gaps; remains case-sensitive.//-commented JS (both new and old forms).Written by Cursor Bugbot for commit 816be46. This will update automatically on new commits. Configure here.