added missing metadata for drop and uniq #4763 (#4908)

* added missing metadata for drop and uniq #4763

* added missing metadata for keep #4763

* added missing metadata for append #4763

* added missing metadata for shuffle #4763
This commit is contained in:
Vishal Sodani 2022-03-23 23:57:01 +05:30 committed by GitHub
parent d32e878868
commit 00b67d338d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 24 additions and 7 deletions

View file

@ -81,12 +81,14 @@ impl Command for Append {
) -> Result<PipelineData, ShellError> {
let val: Value = call.req(engine_state, stack, 0)?;
let vec: Vec<Value> = process_value(val);
let metadata = input.metadata();
Ok(input
.into_iter()
.chain(vec)
.into_iter()
.into_pipeline_data(engine_state.ctrlc.clone()))
.into_pipeline_data(engine_state.ctrlc.clone())
.set_metadata(metadata))
}
}

View file

@ -70,6 +70,7 @@ impl Command for Drop {
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;
@ -81,7 +82,9 @@ impl Command for Drop {
};
if rows_to_drop == 0 {
Ok(v.into_iter().into_pipeline_data(engine_state.ctrlc.clone()))
Ok(v.into_iter()
.into_pipeline_data(engine_state.ctrlc.clone())
.set_metadata(metadata))
} else {
let k = if vlen < rows_to_drop {
0
@ -90,7 +93,9 @@ impl Command for Drop {
};
let iter = v.into_iter().take(k 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

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

View file

@ -29,10 +29,13 @@ impl Command for Shuffle {
_call: &Call,
input: PipelineData,
) -> Result<PipelineData, ShellError> {
let metadata = input.metadata();
let mut v: Vec<_> = input.into_iter().collect();
v.shuffle(&mut thread_rng());
let iter = v.into_iter();
Ok(iter.into_pipeline_data(engine_state.ctrlc.clone()))
Ok(iter
.into_pipeline_data(engine_state.ctrlc.clone())
.set_metadata(metadata))
}
fn examples(&self) -> Vec<Example> {

View file

@ -117,6 +117,7 @@ fn uniq(
let show_repeated = call.has_flag("repeated");
let ignore_case = call.has_flag("ignore-case");
let only_uniques = call.has_flag("unique");
let metadata = input.metadata();
let uniq_values = {
let counter = &mut Vec::new();
@ -180,7 +181,7 @@ fn uniq(
// keeps the original Nushell semantics
if values_vec_deque.len() == 1 {
if let Some(x) = values_vec_deque.pop_front() {
Ok(x.into_pipeline_data())
Ok(x.into_pipeline_data().set_metadata(metadata))
} else {
Err(ShellError::NushellFailed("No input given...".to_string()))
}
@ -189,7 +190,8 @@ fn uniq(
vals: values_vec_deque.into_iter().collect(),
span: head,
}
.into_pipeline_data())
.into_pipeline_data()
.set_metadata(metadata))
}
}