forked from extern/nushell
Add flag for collapsing empty columns
This commit is contained in:
parent
8445cda291
commit
14f6b49483
@ -8,6 +8,8 @@ use log::trace;
|
||||
struct SplitColumnArgs {
|
||||
separator: Tagged<String>,
|
||||
rest: Vec<Tagged<String>>,
|
||||
#[serde(rename(deserialize = "collapse-empty"))]
|
||||
collapse_empty: bool,
|
||||
}
|
||||
|
||||
pub struct SplitColumn;
|
||||
@ -28,12 +30,13 @@ impl WholeStreamCommand for SplitColumn {
|
||||
fn signature(&self) -> Signature {
|
||||
Signature::build("split-column")
|
||||
.required("separator", SyntaxType::Any)
|
||||
.switch("collapse-empty")
|
||||
.rest()
|
||||
}
|
||||
}
|
||||
|
||||
fn split_column(
|
||||
SplitColumnArgs { separator, rest }: SplitColumnArgs,
|
||||
SplitColumnArgs { separator, rest, collapse_empty}: SplitColumnArgs,
|
||||
RunnableContext { input, name, .. }: RunnableContext,
|
||||
) -> Result<OutputStream, ShellError> {
|
||||
Ok(input
|
||||
@ -43,8 +46,8 @@ fn split_column(
|
||||
let splitter = separator.replace("\\n", "\n");
|
||||
trace!("splitting with {:?}", splitter);
|
||||
|
||||
let split_result: Vec<_> = if splitter.chars().all(|c| c.is_whitespace()) {
|
||||
s.split(&splitter).filter(|s| *s != "").collect()
|
||||
let split_result: Vec<_> = if collapse_empty {
|
||||
s.split(&splitter).filter(|s| !s.is_empty()).collect()
|
||||
} else {
|
||||
s.split(&splitter).collect()
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user