mirror of
https://github.com/nushell/nushell.git
synced 2025-04-24 21:28:20 +02:00
support SyntaxShape::OneOf in named args (#13553)
# Description Fixes: #13253 The issue is because nushell use `parse_value` to parse named args, but `parse_value` doesn't parse `OneOf` syntax shape. # User-Facing Changes `OneOf` in named args should works again. # Tests + Formatting I think it's hard to add a test, because nushell doesn't support `oneof` syntax in custom command yet. # After Submitting NaN
This commit is contained in:
parent
0eabbb88dd
commit
a432bf94ec
@ -4701,6 +4701,15 @@ pub fn parse_value(
|
|||||||
| SyntaxShape::String
|
| SyntaxShape::String
|
||||||
| SyntaxShape::GlobPattern
|
| SyntaxShape::GlobPattern
|
||||||
| SyntaxShape::ExternalArgument => {}
|
| SyntaxShape::ExternalArgument => {}
|
||||||
|
SyntaxShape::OneOf(possible_shapes) => {
|
||||||
|
if !possible_shapes
|
||||||
|
.iter()
|
||||||
|
.any(|s| matches!(s, SyntaxShape::List(_)))
|
||||||
|
{
|
||||||
|
working_set.error(ParseError::Expected("non-[] value", span));
|
||||||
|
return Expression::garbage(working_set, span);
|
||||||
|
}
|
||||||
|
}
|
||||||
_ => {
|
_ => {
|
||||||
working_set.error(ParseError::Expected("non-[] value", span));
|
working_set.error(ParseError::Expected("non-[] value", span));
|
||||||
return Expression::garbage(working_set, span);
|
return Expression::garbage(working_set, span);
|
||||||
@ -4778,6 +4787,31 @@ pub fn parse_value(
|
|||||||
}
|
}
|
||||||
|
|
||||||
SyntaxShape::ExternalArgument => parse_regular_external_arg(working_set, span),
|
SyntaxShape::ExternalArgument => parse_regular_external_arg(working_set, span),
|
||||||
|
SyntaxShape::OneOf(possible_shapes) => {
|
||||||
|
for s in possible_shapes {
|
||||||
|
let starting_error_count = working_set.parse_errors.len();
|
||||||
|
let value = parse_value(working_set, span, s);
|
||||||
|
|
||||||
|
if starting_error_count == working_set.parse_errors.len() {
|
||||||
|
return value;
|
||||||
|
} else if let Some(
|
||||||
|
ParseError::Expected(..) | ParseError::ExpectedWithStringMsg(..),
|
||||||
|
) = working_set.parse_errors.last()
|
||||||
|
{
|
||||||
|
working_set.parse_errors.truncate(starting_error_count);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if working_set.parse_errors.is_empty() {
|
||||||
|
working_set.error(ParseError::ExpectedWithStringMsg(
|
||||||
|
format!("one of a list of accepted shapes: {possible_shapes:?}"),
|
||||||
|
span,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
Expression::garbage(working_set, span)
|
||||||
|
}
|
||||||
|
|
||||||
SyntaxShape::Any => {
|
SyntaxShape::Any => {
|
||||||
if bytes.starts_with(b"[") {
|
if bytes.starts_with(b"[") {
|
||||||
|
Loading…
Reference in New Issue
Block a user