mirror of
https://github.com/nushell/nushell.git
synced 2024-11-08 09:34:30 +01:00
parent
2dd4cb9f7d
commit
bd30ea723e
@ -20,7 +20,10 @@ impl Command for Wrap {
|
||||
|
||||
fn signature(&self) -> nu_protocol::Signature {
|
||||
Signature::build("wrap")
|
||||
.input_output_types(vec![(Type::List(Box::new(Type::Any)), Type::Table(vec![]))])
|
||||
.input_output_types(vec![
|
||||
(Type::List(Box::new(Type::Any)), Type::Table(vec![])),
|
||||
(Type::Range, Type::Table(vec![])),
|
||||
])
|
||||
.required("name", SyntaxShape::String, "the name of the column")
|
||||
.category(Category::Filters)
|
||||
}
|
||||
@ -36,7 +39,9 @@ impl Command for Wrap {
|
||||
let name: String = call.req(engine_state, stack, 0)?;
|
||||
|
||||
match input {
|
||||
PipelineData::Value(Value::List { vals, .. }, ..) => Ok(vals
|
||||
PipelineData::Value(Value::Range { .. }, ..)
|
||||
| PipelineData::Value(Value::List { .. }, ..)
|
||||
| PipelineData::ListStream { .. } => Ok(input
|
||||
.into_iter()
|
||||
.map(move |x| Value::Record {
|
||||
cols: vec![name.clone()],
|
||||
@ -44,13 +49,6 @@ impl Command for Wrap {
|
||||
span,
|
||||
})
|
||||
.into_pipeline_data(engine_state.ctrlc.clone())),
|
||||
PipelineData::ListStream(stream, ..) => Ok(stream
|
||||
.map(move |x| Value::Record {
|
||||
cols: vec![name.clone()],
|
||||
vals: vec![x],
|
||||
span,
|
||||
})
|
||||
.into_pipeline_data(engine_state.ctrlc.clone())),
|
||||
PipelineData::ExternalStream { .. } => Ok(Value::Record {
|
||||
cols: vec![name],
|
||||
vals: vec![input.into_value(call.head)],
|
||||
@ -67,30 +65,56 @@ impl Command for Wrap {
|
||||
}
|
||||
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
vec![Example {
|
||||
description: "Wrap a list into a table with a given column name",
|
||||
example: "[1 2 3] | wrap num",
|
||||
result: Some(Value::List {
|
||||
vals: vec![
|
||||
Value::Record {
|
||||
cols: vec!["num".into()],
|
||||
vals: vec![Value::test_int(1)],
|
||||
span: Span::test_data(),
|
||||
},
|
||||
Value::Record {
|
||||
cols: vec!["num".into()],
|
||||
vals: vec![Value::test_int(2)],
|
||||
span: Span::test_data(),
|
||||
},
|
||||
Value::Record {
|
||||
cols: vec!["num".into()],
|
||||
vals: vec![Value::test_int(3)],
|
||||
span: Span::test_data(),
|
||||
},
|
||||
],
|
||||
span: Span::test_data(),
|
||||
}),
|
||||
}]
|
||||
vec![
|
||||
Example {
|
||||
description: "Wrap a list into a table with a given column name",
|
||||
example: "[1 2 3] | wrap num",
|
||||
result: Some(Value::List {
|
||||
vals: vec![
|
||||
Value::Record {
|
||||
cols: vec!["num".into()],
|
||||
vals: vec![Value::test_int(1)],
|
||||
span: Span::test_data(),
|
||||
},
|
||||
Value::Record {
|
||||
cols: vec!["num".into()],
|
||||
vals: vec![Value::test_int(2)],
|
||||
span: Span::test_data(),
|
||||
},
|
||||
Value::Record {
|
||||
cols: vec!["num".into()],
|
||||
vals: vec![Value::test_int(3)],
|
||||
span: Span::test_data(),
|
||||
},
|
||||
],
|
||||
span: Span::test_data(),
|
||||
}),
|
||||
},
|
||||
Example {
|
||||
description: "Wrap a range into a table with a given column name",
|
||||
example: "1..3 | wrap num",
|
||||
result: Some(Value::List {
|
||||
vals: vec![
|
||||
Value::Record {
|
||||
cols: vec!["num".into()],
|
||||
vals: vec![Value::test_int(1)],
|
||||
span: Span::test_data(),
|
||||
},
|
||||
Value::Record {
|
||||
cols: vec!["num".into()],
|
||||
vals: vec![Value::test_int(2)],
|
||||
span: Span::test_data(),
|
||||
},
|
||||
Value::Record {
|
||||
cols: vec!["num".into()],
|
||||
vals: vec![Value::test_int(3)],
|
||||
span: Span::test_data(),
|
||||
},
|
||||
],
|
||||
span: Span::test_data(),
|
||||
}),
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user