Skip to content

Add extern --strict to reject undeclared flags - #19313

Merged
fdncred merged 1 commit into
nushell:mainfrom
fdncred:extern_strict
Oct 23, 2026
Merged

fdncred merged 1 commit into
nushell:mainfrom
fdncred:extern_strict

Conversation

@fdncred

@fdncred fdncred commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Description

An extern signature drives completions, but it doesn't guard anything. extern "git status" [--short(-s)]; git status --shrt passes --shrt to git, and git prints its own usage error. That's because externs accept unknown arguments, so nushell can wrap a tool without declaring every flag it has.

extern --strict (and export extern --strict) turns a flag the signature doesn't declare into a parse error, with the "Did you mean" hint that internal commands already give. Everything else an extern accepts still works: positional arguments, -- and the arguments after it all reach the tool. --help is always allowed, so git status --help still shows git's help. -h isn't exempt, since it means something else for some tools (ls -h, grep -h).

Before & After

Command Before PR After PR
extern --strict "git status" [--short(-s)]; git status --shrt The `extern` command doesn't have flag `strict`. The `git status` command doesn't have flag `shrt`., help: Did you mean: `--short`?
extern --strict "git status" [--short(-s)]; git status -x same strict error The `git status` command doesn't have flag `-x`.
extern --strict "git status" [--short(-s)]; git status -s -- --shrt same strict error runs git status -s -- --shrt
extern --strict "git status" [--short(-s)]; git status --help same strict error git's help
module g { export extern --strict "git status" [--short(-s)] }; use g "git status"; git status --shrt same strict error The `git status` command doesn't have flag `shrt`.
extern "git status" [--short(-s)]; git status --shrt git: error: unknown option `shrt' same
extern --strict printf []; printf "%s|" -10 same strict error -10|
extern --strict printf []; let n = 3; let f = "x"; printf "%s|" -$n -($n) --($f) same strict error -$n|-3|--x|
extern printf [--x: string]; printf "%s|" --x (ls --bogus) hello --x|hello| The `ls` command doesn't have flag `bogus`.
def --wrapped w [--x: string, ...rest] { $rest | to nuon }; w --x (ls --bogus) hello [--x, hello] The `ls` command doesn't have flag `bogus`.

User-facing changes (Release notes)

Catch undeclared flags with extern --strict

extern --strict and export extern --strict now reject undeclared flags with a parse error and a "Did you mean" hint for matching declared flags, helping catch typos before running an external command. Positional arguments, -- and the arguments after it still reach the command. --help is always allowed; -h must be declared. Externs without --strict continue to accept undeclared flags.

Unknown flags inside a declared flag's value, as in cmd --x (ls --bogus), are now reported for externs and def --wrapped commands instead of silently dropping the error and passing --x without its value.

Additional notes

@github-actions github-actions Bot added the A:parser Issues related to parsing label Oct 22, 2026
@fdncred fdncred added notes:ready Indicates Ready for Release notes notes:additions Noted in "Additions" section labels Oct 23, 2026
@fdncred
fdncred merged commit 02d39b8 into nushell:main Oct 23, 2026
12 checks passed
@github-actions github-actions Bot added this to the v0.117.0 milestone Oct 23, 2026
@fdncred
fdncred deleted the extern_strict branch November 16, 2026 18:03
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:additions Noted in "Additions" section notes:ready Indicates Ready for Release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant