Introduce metadata into the pipeline (#397)

This commit is contained in:
JT
2021-12-02 18:59:10 +13:00
committed by GitHub
parent 56307553ae
commit 45eba8b922
28 changed files with 329 additions and 199 deletions

View File

@ -57,14 +57,14 @@ pub fn eval(
) -> Result<PipelineData, ShellError> {
if let Some(expr) = spanned_expr {
match parse(&expr.item, &expr.span) {
Ok(value) => Ok(PipelineData::Value(value)),
Ok(value) => Ok(PipelineData::Value(value, None)),
Err(err) => Err(ShellError::UnsupportedInput(
format!("Math evaluation error: {}", err),
expr.span,
)),
}
} else {
if let PipelineData::Value(Value::Nothing { .. }) = input {
if let PipelineData::Value(Value::Nothing { .. }, ..) = input {
return Ok(input);
}
input.map(

View File

@ -62,12 +62,12 @@ pub fn calculate(
mf: impl Fn(&[Value], &Span) -> Result<Value, ShellError>,
) -> Result<Value, ShellError> {
match values {
PipelineData::Stream(s) => helper_for_tables(&s.collect::<Vec<Value>>(), name, mf),
PipelineData::Value(Value::List { ref vals, .. }) => match &vals[..] {
PipelineData::Stream(s, ..) => helper_for_tables(&s.collect::<Vec<Value>>(), name, mf),
PipelineData::Value(Value::List { ref vals, .. }, ..) => match &vals[..] {
[Value::Record { .. }, _end @ ..] => helper_for_tables(vals, name, mf),
_ => mf(vals, &name),
},
PipelineData::Value(Value::Record { vals, cols, span }) => {
PipelineData::Value(Value::Record { vals, cols, span }, ..) => {
let new_vals: Result<Vec<Value>, ShellError> =
vals.into_iter().map(|val| mf(&[val], &name)).collect();
match new_vals {
@ -79,7 +79,7 @@ pub fn calculate(
Err(err) => Err(err),
}
}
PipelineData::Value(Value::Range { val, .. }) => {
PipelineData::Value(Value::Range { val, .. }, ..) => {
let new_vals: Result<Vec<Value>, ShellError> = val
.into_range_iter()?
.map(|val| mf(&[val], &name))
@ -87,6 +87,6 @@ pub fn calculate(
mf(&new_vals?, &name)
}
PipelineData::Value(val) => mf(&[val], &name),
PipelineData::Value(val, ..) => mf(&[val], &name),
}
}