Repository navigation
Add "fall-through" signatures - #7527
Conversation
|
unknown flags, yay! excited to see this work |
| } | ||
| spans_idx += 1; | ||
| } else { | ||
| error = error.or_else(|| { |
There was a problem hiding this comment.
Hi, I think we need to check if !signature.allows_unknown_flag here, we may only need to make the error if it's not allows_unknown_flag, to address #5103
There was a problem hiding this comment.
Interesting, yeah git push --force-with-lease doesn't work. I think we should still report missing flag parameter if the flag requires it. extern spam [--foo: string] should report error if you call just spam --foo. But git push --force-with-lease doesn't require a parameter, so there is something wrong here.
There was a problem hiding this comment.
|
To fix the issue: #6020, I think we need to check nushell/crates/nu-parser/src/parser.rs Lines 938 to 945 in 5f48452 I don't think we need to return |
| let (arg, arg_err) = parse_value( | ||
| working_set, | ||
| arg_span, | ||
| &SyntaxShape::Any, |
There was a problem hiding this comment.
Hi, I don't really understand why we need to use SyntaxShape::Any rather than SyntaxShape::String?
There was a problem hiding this comment.
Because we want to pass also other expressions that evaluate to a string, such as variables ($foo), subexpressions (([a b c] | str collect ' ')), etc. So what I did is I allowed all expressions and left the type checking up to the runtime.
@WindSoilder We want to report a situation where you define that the command requires a positional but you don't supply it. Example: |
|
@WindSoilder I see where you're going with adding the |
|
@kubouch Yeah, that's fine :-) Thanks for your implementation, I never thought about adding |
|
Awesome, glad to see this fix land. Thank you all for your work. :) |
Description
Adds a "fall-through" type of signature which does not throw errors if is called with unknown flags/positionals. This type of signatures is enabled for known externals defined with
externand theexecbuilt-in command.The PR is a continuation of #6567 made by @merelymyself and #7461 made by @WindSoilder.
Fixes #4659. Fixes #5294. Fixes #6124.
Does not fix: #5103
Problematic flags
These flags remain somewhat tricky:
-0: gets parsed as0integer and re-printed as0instead of-0-h,--help: Prints the help message ofexecand doesn't pass the flag to the external. If defined asexternthe command will pass the-hflag to the external but won't print the help message.User-Facing Changes
externnow allow unknown argumentsexecnow allows unknown arguments same as known externalexecargument handling so their behavior is consistent with running other externals (e.g.,exec foo $x [ a b c ] -90will now work correctly)$nu.plugin-fileand re-registerall of your plugins.Tests + Formatting
Don't forget to add tests that cover your changes.
Make sure you've run and fixed any issues with these commands:
cargo fmt --all -- --checkto check standard code formatting (cargo fmt --allapplies these changes)cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collectto check that you're using the standard code stylecargo test --workspaceto check that all tests passAfter Submitting
If your PR had any user-facing changes, update the documentation after the PR is merged, if necessary. This will help us keep the docs up to date.