forked from extern/nushell
Merge pull request #251 from nushell/better_split_column
Use different helper functions for split column
This commit is contained in:
commit
a2c2a07638
@ -54,7 +54,7 @@ fn split_column(
|
|||||||
let rest: Vec<Spanned<String>> = call.rest(engine_state, stack, 1)?;
|
let rest: Vec<Spanned<String>> = call.rest(engine_state, stack, 1)?;
|
||||||
let collapse_empty = call.has_flag("collapse-empty");
|
let collapse_empty = call.has_flag("collapse-empty");
|
||||||
|
|
||||||
input.map(move |x| split_column_helper(&x, &separator, &rest, collapse_empty, name_span))
|
input.flat_map(move |x| split_column_helper(&x, &separator, &rest, collapse_empty, name_span))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn split_column_helper(
|
fn split_column_helper(
|
||||||
@ -63,7 +63,7 @@ fn split_column_helper(
|
|||||||
rest: &[Spanned<String>],
|
rest: &[Spanned<String>],
|
||||||
collapse_empty: bool,
|
collapse_empty: bool,
|
||||||
head: Span,
|
head: Span,
|
||||||
) -> Value {
|
) -> Vec<Value> {
|
||||||
if let Ok(s) = v.as_string() {
|
if let Ok(s) = v.as_string() {
|
||||||
let splitter = separator.item.replace("\\n", "\n");
|
let splitter = separator.item.replace("\\n", "\n");
|
||||||
|
|
||||||
@ -95,24 +95,21 @@ fn split_column_helper(
|
|||||||
vals.push(Value::string(k, head));
|
vals.push(Value::string(k, head));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Value::List {
|
vec![Value::Record {
|
||||||
vals: vec![Value::Record {
|
cols,
|
||||||
cols,
|
vals,
|
||||||
vals,
|
|
||||||
span: head,
|
|
||||||
}],
|
|
||||||
span: head,
|
span: head,
|
||||||
}
|
}]
|
||||||
} else {
|
} else {
|
||||||
match v.span() {
|
match v.span() {
|
||||||
Ok(span) => Value::Error {
|
Ok(span) => vec![Value::Error {
|
||||||
error: ShellError::PipelineMismatch {
|
error: ShellError::PipelineMismatch {
|
||||||
expected: Type::String,
|
expected: Type::String,
|
||||||
expected_span: head,
|
expected_span: head,
|
||||||
origin: span,
|
origin: span,
|
||||||
},
|
},
|
||||||
},
|
}],
|
||||||
Err(error) => Value::Error { error },
|
Err(error) => vec![Value::Error { error }],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user