fix: lose ls_colors in some filters commands (#4525)

* feat: add metadata to first

* feat: add metadata to last and skip

* feat: add metadata to reverse

* fix: apply clippy
This commit is contained in:
Jae-Heon Ji 2022-02-21 23:29:51 +09:00 committed by GitHub
parent a2c4c92fce
commit d1ec05b12b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 37 additions and 17 deletions

View File

@ -2,8 +2,8 @@ use nu_engine::CallExt;
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{
Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, SyntaxShape,
Type, Value,
Category, Example, IntoInterruptiblePipelineData, IntoPipelineData, PipelineData, ShellError,
Signature, Span, SyntaxShape, Type, Value,
};
#[derive(Clone)]
@ -70,6 +70,9 @@ fn first_helper(
None => 1,
};
let ctrlc = engine_state.ctrlc.clone();
let metadata = input.metadata();
let mut input_peek = input.into_iter().peekable();
if input_peek.peek().is_some() {
match input_peek
@ -125,11 +128,11 @@ fn first_helper(
_ => todo!(),
},
None => Ok(Value::List {
vals: input_peek.into_iter().take(rows_desired).collect(),
span: head,
}
.into_pipeline_data()),
None => Ok(input_peek
.into_iter()
.take(rows_desired)
.into_pipeline_data(ctrlc)
.set_metadata(metadata)),
}
}
_ => {
@ -139,11 +142,11 @@ fn first_helper(
None => Err(ShellError::AccessBeyondEndOfStream(head)),
}
} else {
Ok(Value::List {
vals: input_peek.into_iter().take(rows_desired).collect(),
span: head,
}
.into_pipeline_data())
Ok(input_peek
.into_iter()
.take(rows_desired)
.into_pipeline_data(ctrlc)
.set_metadata(metadata))
}
}
}

View File

@ -47,6 +47,8 @@ impl Command for Last {
call: &Call,
input: PipelineData,
) -> Result<PipelineData, ShellError> {
let metadata = input.metadata();
let rows: Option<i64> = call.opt(engine_state, stack, 0)?;
let v: Vec<_> = input.into_iter().collect();
let vlen: i64 = v.len() as i64;
@ -54,7 +56,9 @@ impl Command for Last {
let iter = v.into_iter().skip(beginning_rows_to_skip as usize);
Ok(iter.into_pipeline_data(engine_state.ctrlc.clone()))
Ok(iter
.into_pipeline_data(engine_state.ctrlc.clone())
.set_metadata(metadata))
}
}

View File

@ -44,10 +44,14 @@ impl Command for Reverse {
_call: &Call,
input: PipelineData,
) -> Result<PipelineData, ShellError> {
let metadata = input.metadata();
#[allow(clippy::needless_collect)]
let v: Vec<_> = input.into_iter().collect();
let iter = v.into_iter().rev();
Ok(iter.into_pipeline_data(engine_state.ctrlc.clone()))
Ok(iter
.into_pipeline_data(engine_state.ctrlc.clone())
.set_metadata(metadata))
}
}

View File

@ -60,6 +60,7 @@ impl Command for Skip {
) -> Result<PipelineData, ShellError> {
let n: Option<Value> = call.opt(engine_state, stack, 0)?;
let span = call.head;
let metadata = input.metadata();
let n: usize = match n {
Some(Value::Int { val, span }) => val.try_into().map_err(|err| {
@ -74,7 +75,11 @@ impl Command for Skip {
let ctrlc = engine_state.ctrlc.clone();
Ok(input.into_iter().skip(n).into_pipeline_data(ctrlc))
Ok(input
.into_iter()
.skip(n)
.into_pipeline_data(ctrlc)
.set_metadata(metadata))
}
}

View File

@ -47,6 +47,7 @@ impl Command for SkipUntil {
input: PipelineData,
) -> Result<PipelineData, ShellError> {
let span = call.head;
let metadata = input.metadata();
let capture_block: CaptureBlock = call.req(engine_state, stack, 0)?;
@ -69,7 +70,8 @@ impl Command for SkipUntil {
pipeline_data.into_value(span).is_true()
})
})
.into_pipeline_data(ctrlc))
.into_pipeline_data(ctrlc)
.set_metadata(metadata))
}
}

View File

@ -47,6 +47,7 @@ impl Command for SkipWhile {
input: PipelineData,
) -> Result<PipelineData, ShellError> {
let span = call.head;
let metadata = input.metadata();
let capture_block: CaptureBlock = call.req(engine_state, stack, 0)?;
@ -69,7 +70,8 @@ impl Command for SkipWhile {
pipeline_data.into_value(span).is_true()
})
})
.into_pipeline_data(ctrlc))
.into_pipeline_data(ctrlc)
.set_metadata(metadata))
}
}