mirror of
https://github.com/nushell/nushell.git
synced 2024-11-22 16:33:37 +01:00
Extract common logic for setting error in parse_short_flags
(#10709)
# Description Since the `else` clause for the nested branches check for the first unmatched argument, this PR brings together all the conditions where the positional argument shape is numeric using the `matches!` keyword. This also allows us to and (`&&`) the condition with when no short flags are found unlike the `if let ...` statements. Finally, we can handle any `unmatched_short_flags` at one place. # User-Facing Changes No user facing changes.
This commit is contained in:
parent
27e6271402
commit
b907939916
@ -474,53 +474,28 @@ fn parse_short_flags(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if found_short_flags.is_empty() {
|
if found_short_flags.is_empty()
|
||||||
let arg_contents = working_set.get_span_contents(arg_span);
|
|
||||||
|
|
||||||
// check to see if we have a negative number
|
// check to see if we have a negative number
|
||||||
if let Some(positional) = sig.get_positional(positional_idx) {
|
&& matches!(
|
||||||
if positional.shape == SyntaxShape::Int
|
sig.get_positional(positional_idx),
|
||||||
|| positional.shape == SyntaxShape::Number
|
Some(PositionalArg {
|
||||||
{
|
shape: SyntaxShape::Int | SyntaxShape::Number,
|
||||||
if String::from_utf8_lossy(arg_contents).parse::<f64>().is_ok() {
|
..
|
||||||
return None;
|
})
|
||||||
} else if let Some(first) = unmatched_short_flags.first() {
|
)
|
||||||
let contents = working_set.get_span_contents(*first);
|
&& String::from_utf8_lossy(working_set.get_span_contents(arg_span))
|
||||||
working_set.error(ParseError::UnknownFlag(
|
.parse::<f64>()
|
||||||
sig.name.clone(),
|
.is_ok()
|
||||||
format!("-{}", String::from_utf8_lossy(contents)),
|
{
|
||||||
*first,
|
return None;
|
||||||
sig.clone().formatted_flags(),
|
} else if let Some(first) = unmatched_short_flags.first() {
|
||||||
));
|
let contents = working_set.get_span_contents(*first);
|
||||||
}
|
working_set.error(ParseError::UnknownFlag(
|
||||||
} else if let Some(first) = unmatched_short_flags.first() {
|
sig.name.clone(),
|
||||||
let contents = working_set.get_span_contents(*first);
|
format!("-{}", String::from_utf8_lossy(contents)),
|
||||||
working_set.error(ParseError::UnknownFlag(
|
*first,
|
||||||
sig.name.clone(),
|
sig.clone().formatted_flags(),
|
||||||
format!("-{}", String::from_utf8_lossy(contents)),
|
));
|
||||||
*first,
|
|
||||||
sig.clone().formatted_flags(),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
} else if let Some(first) = unmatched_short_flags.first() {
|
|
||||||
let contents = working_set.get_span_contents(*first);
|
|
||||||
working_set.error(ParseError::UnknownFlag(
|
|
||||||
sig.name.clone(),
|
|
||||||
format!("-{}", String::from_utf8_lossy(contents)),
|
|
||||||
*first,
|
|
||||||
sig.clone().formatted_flags(),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
} else if !unmatched_short_flags.is_empty() {
|
|
||||||
if let Some(first) = unmatched_short_flags.first() {
|
|
||||||
let contents = working_set.get_span_contents(*first);
|
|
||||||
working_set.error(ParseError::UnknownFlag(
|
|
||||||
sig.name.clone(),
|
|
||||||
format!("-{}", String::from_utf8_lossy(contents)),
|
|
||||||
*first,
|
|
||||||
sig.clone().formatted_flags(),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Some(found_short_flags)
|
Some(found_short_flags)
|
||||||
|
Loading…
Reference in New Issue
Block a user