Improve external output in subexprs (#294)

This commit is contained in:
JT
2021-11-06 18:50:33 +13:00
committed by GitHub
parent c7d159a0f3
commit 02b8027749
50 changed files with 320 additions and 136 deletions

View File

@ -41,7 +41,7 @@ impl Command for SubCommand {
pub fn maximum(values: &[Value], head: &Span) -> Result<Value, ShellError> {
let max_func = reducer_for(Reduce::Maximum);
max_func(Value::nothing(), values.to_vec(), *head)
max_func(Value::nothing(*head), values.to_vec(), *head)
}
#[cfg(test)]

View File

@ -41,7 +41,7 @@ impl Command for SubCommand {
pub fn minimum(values: &[Value], head: &Span) -> Result<Value, ShellError> {
let min_func = reducer_for(Reduce::Minimum);
min_func(Value::nothing(), values.to_vec(), *head)
min_func(Value::nothing(*head), values.to_vec(), *head)
}
#[cfg(test)]

View File

@ -42,7 +42,7 @@ impl Command for SubCommand {
/// Calculate product of given values
pub fn product(values: &[Value], head: &Span) -> Result<Value, ShellError> {
let product_func = reducer_for(Reduce::Product);
product_func(Value::nothing(), values.to_vec(), *head)
product_func(Value::nothing(*head), values.to_vec(), *head)
}
#[cfg(test)]

View File

@ -24,7 +24,7 @@ pub fn reducer_for(command: Reduce) -> ReducerFunction {
pub fn max(data: Vec<Value>, head: Span) -> Result<Value, ShellError> {
let mut biggest = data
.first()
.ok_or_else(|| ShellError::UnsupportedInput("Empty input".to_string(), Span::unknown()))?
.ok_or_else(|| ShellError::UnsupportedInput("Empty input".to_string(), head))?
.clone();
for value in &data {
@ -48,7 +48,7 @@ pub fn max(data: Vec<Value>, head: Span) -> Result<Value, ShellError> {
pub fn min(data: Vec<Value>, head: Span) -> Result<Value, ShellError> {
let mut smallest = data
.first()
.ok_or_else(|| ShellError::UnsupportedInput("Empty input".to_string(), Span::unknown()))?
.ok_or_else(|| ShellError::UnsupportedInput("Empty input".to_string(), head))?
.clone();
for value in &data {
@ -87,9 +87,9 @@ pub fn sum(data: Vec<Value>, head: Span) -> Result<Value, ShellError> {
}),
None => Err(ShellError::UnsupportedInput(
"Empty input".to_string(),
Span::unknown(),
head,
)),
_ => Ok(Value::nothing()),
_ => Ok(Value::nothing(head)),
}?;
for value in &data {
@ -127,7 +127,7 @@ pub fn product(data: Vec<Value>, head: Span) -> Result<Value, ShellError> {
"Empty input".to_string(),
Span::unknown(),
)),
_ => Ok(Value::nothing()),
_ => Ok(Value::nothing(head)),
}?;
for value in &data {

View File

@ -48,7 +48,7 @@ impl Command for SubCommand {
pub fn summation(values: &[Value], head: &Span) -> Result<Value, ShellError> {
let sum_func = reducer_for(Reduce::Summation);
sum_func(Value::nothing(), values.to_vec(), *head)
sum_func(Value::nothing(*head), values.to_vec(), *head)
}
#[cfg(test)]