fix(cli): preserve double dash before entrypoint - #36794
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The new positional_only path diverges from existing trailing/---stripping and unexpected-positional error behavior, which can mis-handle argv in real CLI invocations.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR updates the libs/cli_parser argument parser to treat -- as an end-of-options separator before the first positional “entrypoint” (ex: deno run -- -echo.ts), restoring behavior needed for leading-hyphen scripts/code and keeping post-entrypoint arguments routed to trailing args.
Changes:
- Add a
positional_onlyparsing mode to consume initial positionals after--without interpreting leading-as flags. - Preserve existing trailing-arg behavior after the entrypoint (including
keep_double_dashsemantics). - Add regression tests covering
run -- <script>andeval -- <code>.
File summaries
| File | Description |
|---|---|
| libs/cli_parser/src/parse.rs | Implements positional_only parsing after -- prior to the first positional. |
| libs/cli_parser/src/tests.rs | Adds parser regressions for run and eval using -- before entrypoint/code. |
Review details
Suppressed comments (1)
libs/cli_parser/src/parse.rs:192
- When
positional_onlyis active and there are more argv tokens than there are positional defs, the parser currently pushes the extras intoresult.trailingunconditionally. That differs from the normal parsing path (which errors withUnexpectedPositionalwhentrailing_var_argis false) and can cause commands likedeno info -- -file.ts extrato be accepted unexpectedly.
result.trailing.push(arg.clone());
i += 1;
continue;
- Files reviewed: 2/2 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
Addressed the Copilot review in commit |
Summary
--as an end-of-options separator before the first positional entrypointrun,eval, and root-script formsValidation
cargo test -p deno_cli_parser --lib --offline --features deno_core/v8: 379 passeddenobinary built successfullyeval --,run --, leading-hyphen scripts, and trailing arguments passedcargo fmt --all -- --checkpassedgit diff --checkpassed./x checkwas stopped after it expanded into a full-repository compile beyond this two-file parser change.Fixes #36792
AI assistance disclosure
This PR was prepared with assistance from ChatGPT/Codex.