Skip to content

fix(parser): pass -Zscript and -j8 through to a known external - #19642

Merged
fdncred merged 1 commit into
nushell:mainfrom
fdncred:extern_attached_short_value
Nov 24, 2026
Merged

fdncred merged 1 commit into
nushell:mainfrom
fdncred:extern_attached_short_value

Conversation

@fdncred

@fdncred fdncred commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Description

generate completions cargo declares -Z: string, and with that extern loaded, cargo -Zscript foo.rs failed with only_last_flag_in_batch_can_take_arg. ^cargo -Zscript and cargo -Z script both worked. make -j8 and git commit -amf failed the same way under their externs. git commit -amf is the example in #5923, which #8808 closed by letting the last flag in a batch take the next word. The attached form never worked.

A known external now reads short flags the way getopt does. When a flag that takes a value comes before the end of the word, the rest of the word is its value, and the word goes to the program as written. Nushell still checks that value against the flag's type, so -jabc with -j: int fails like -j abc does. extern --strict accepts the word when every flag in it is declared. Nushell commands and def --wrapped keep the old rule.

> cargo -Zscript fp_asm.rs        # before
Error: nu::parser::only_last_flag_in_batch_can_take_arg

  × Only the last flag in a short flag batch can take an argument.
   ╭─[source:1:37]
 1 │ source cargo_completions.nu; cargo -Zscript fp_asm.rs | complete | reject stdout
   ·                                     ┬
   ·                                     ╰── only the last flag can take args

> cargo -Zscript fp_asm.rs        # after, on stable cargo
error: the `-Z` flag is only accepted on the nightly channel of Cargo, but this is the `stable` channel

User-facing changes (Release notes)

Commands declared with extern accept a short flag with its value attached, such as cargo -Zscript, make -j8 or git commit -amf, and pass it to the program as written.

Additional notes

closes #19639

  • Values that start with $ or ( skip the type check. Inside the word, -Z$x stays literal and -Z(1 + 2) becomes -Z3, so checking $x or (1 + 2) alone would test something the program never gets.
  • The last-flag check also had a bug. It compared a byte offset with a character count, so in -éjm 5 the -j took a value without being last. It now compares spans.

…(parser): pass `-Zscript` and `-j8` through to a known external
@github-actions github-actions Bot added the A:parser Issues related to parsing label Nov 23, 2026
@fdncred fdncred added notes:fixes Noted in "Bug fixes" section notes:ready Indicates Ready for Release notes labels Nov 24, 2026
@fdncred
fdncred merged commit a349f32 into nushell:main Nov 24, 2026
15 checks passed
@fdncred
fdncred deleted the extern_attached_short_value branch November 24, 2026 15:43
@github-actions github-actions Bot added this to the v0.118.0 milestone Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A:parser Issues related to parsing notes:fixes Noted in "Bug fixes" section notes:ready Indicates Ready for Release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

REPL error "only the last flag can take args" for a short flag with an argument not separated by a space

1 participant