Repository navigation
Add extern --strict to reject undeclared flags - #19313
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
An
externsignature drives completions, but it doesn't guard anything.extern "git status" [--short(-s)]; git status --shrtpasses--shrtto 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(andexport 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.--helpis always allowed, sogit status --helpstill shows git's help.-hisn't exempt, since it means something else for some tools (ls -h,grep -h).Before & After
extern --strict "git status" [--short(-s)]; git status --shrtThe `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 -xstricterrorThe `git status` command doesn't have flag `-x`.extern --strict "git status" [--short(-s)]; git status -s -- --shrtstricterrorgit status -s -- --shrtextern --strict "git status" [--short(-s)]; git status --helpstricterrormodule g { export extern --strict "git status" [--short(-s)] }; use g "git status"; git status --shrtstricterrorThe `git status` command doesn't have flag `shrt`.extern "git status" [--short(-s)]; git status --shrterror: unknown option `shrt'extern --strict printf []; printf "%s|" -10stricterror-10|extern --strict printf []; let n = 3; let f = "x"; printf "%s|" -$n -($n) --($f)stricterror-$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 --strictextern --strictandexport extern --strictnow 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.--helpis always allowed;-hmust be declared. Externs without--strictcontinue to accept undeclared flags.Unknown flags inside a declared flag's value, as in
cmd --x (ls --bogus), are now reported for externs anddef --wrappedcommands instead of silently dropping the error and passing--xwithout its value.Additional notes