src: list scripts when --run has no command - #64606
Conversation
|
Review requested:
|
| // `--run` may be passed without a script name to list available scripts, | ||
| // so an omitted value is not an error and must not swallow a later flag. | ||
| const bool optional_value = name == "--run"; |
There was a problem hiding this comment.
Is there a better solution to modifying the options parser directly? We have other CLI flags that have different behavior depending on whether or not they have an argument passed?
How does --inspect do this?
There was a problem hiding this comment.
I'm not entirely familiar with the code, but looking at --inspect, it's a boolean option so works a bit differently I think:
Lines 475 to 479 in 0bcc6ef
So --inspect and --inspect=1234 work, but --inspect 1234 isn't valid.
If I'm understanding correctly, --run can't do this, because it's space separated.
To avoid the hardcoded name == "--run", what would you suggest?
There was a problem hiding this comment.
hmm, perhaps I was mis-remembering that --inspect required an = to run 😓. I'm still wary about changing the parser, since there probably should be a way for a flag to be passed with an optional value, regardless of =.
Sorry about misremembering, I'll ask around to see if there's a way to do this, and if not, we can always add it.
There was a problem hiding this comment.
thanks! It's also very possible I'm misreading this or missing something, and this is already supported somewhere - sorry if so!
There was a problem hiding this comment.
I doubt that, you (so far) demonstrate a great understanding of the codebase. It's probable that we just never encountered this scenario before.
Great work so far :-)
|
Implementation LGTM. I'm not giving this the green check while I look into better ways of actually detecting the option-less flag, but everything from that point on is great :) |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #64606 +/- ##
=======================================
Coverage 90.14% 90.15%
=======================================
Files 746 746
Lines 242763 242775 +12
Branches 45761 45773 +12
=======================================
+ Hits 218848 218867 +19
+ Misses 15402 15397 -5
+ Partials 8513 8511 -2
🚀 New features to boost your workflow:
|
|
Just pushed to fix the markdown linting - looks like I needed to prepend to The macOS test failure looks to be an unrelated flake, but let me know if not. |
|
Thank you James! @Cherry |
This comment was marked as outdated.
This comment was marked as outdated.
|
GHA is borked on the current PR head, and looks like there will be lint issues to address anyway, so I'm just going to trigger a rebase. |
a39f0dc to
95d7a9a
Compare
|
Let me know if I can help with any of the linting (etc.) issues! Thanks all. |
@Cherry can you rebase and ask your agent to fix the linting errors please? |
|
The only complaint appears to be: |
|
Yeah I can rebase and try and fix that shortly! |
Signed-off-by: James Ross <james@jross.me>
|
Should be good now, thanks! |
This extends the behaviour when you run
node --run <unknown script>that prints a list of available scripts, to now print available scripts when you simply runnode --run, to mimic the behaviour ofnpm run, etc.Previously,
node --runwith no command errored with--run requires an argument.This is my first contribution to Node.js so while I've tried to read and follow everything, please let me know if I'm missing anything!
Fixes: #64870