This commit is contained in:
JT
2021-10-26 10:14:21 +13:00
parent d29208dd9e
commit 85a69c0a45
14 changed files with 151 additions and 120 deletions

View File

@ -4,9 +4,7 @@ use unicode_segmentation::UnicodeSegmentation;
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{
Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, Type, Value,
};
use nu_protocol::{Example, PipelineData, ShellError, Signature, Span, Type, Value};
#[derive(Clone)]
pub struct Size;
@ -104,18 +102,16 @@ impl Command for Size {
fn size(call: &Call, input: PipelineData) -> Result<PipelineData, ShellError> {
let span = call.head;
Ok(input
.map(move |v| match v.as_string() {
Ok(s) => count(&s, span),
Err(_) => Value::Error {
error: ShellError::PipelineMismatch {
expected: Type::String,
expected_span: span,
origin: span,
},
input.map(move |v| match v.as_string() {
Ok(s) => count(&s, span),
Err(_) => Value::Error {
error: ShellError::PipelineMismatch {
expected: Type::String,
expected_span: span,
origin: span,
},
})
.into_pipeline_data())
},
})
}
fn count(contents: &str, span: Span) -> Value {

View File

@ -1,7 +1,7 @@
use nu_protocol::{
ast::Call,
engine::{Command, EngineState, Stack},
Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, Type, Value,
Example, PipelineData, ShellError, Signature, Span, Type, Value,
};
#[derive(Clone)]
@ -54,9 +54,7 @@ fn split_chars(
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
let span = call.head;
Ok(input
.flat_map(move |x| split_chars_helper(&x, span))
.into_pipeline_data())
input.flat_map(move |x| split_chars_helper(&x, span))
}
fn split_chars_helper(v: &Value, name: Span) -> Vec<Value> {

View File

@ -2,7 +2,7 @@ use nu_engine::CallExt;
use nu_protocol::{
ast::Call,
engine::{Command, EngineState, Stack},
IntoPipelineData, PipelineData, ShellError, Signature, Span, Spanned, SyntaxShape, Type, Value,
PipelineData, ShellError, Signature, Span, Spanned, SyntaxShape, Type, Value,
};
#[derive(Clone)]
@ -54,9 +54,7 @@ fn split_column(
let rest: Vec<Spanned<String>> = call.rest(engine_state, stack, 1)?;
let collapse_empty = call.has_flag("collapse-empty");
Ok(input
.map(move |x| split_column_helper(&x, &separator, &rest, collapse_empty, name_span))
.into_pipeline_data())
input.map(move |x| split_column_helper(&x, &separator, &rest, collapse_empty, name_span))
}
fn split_column_helper(

View File

@ -2,7 +2,7 @@ use nu_engine::CallExt;
use nu_protocol::{
ast::Call,
engine::{Command, EngineState, Stack},
IntoPipelineData, PipelineData, ShellError, Signature, Span, Spanned, SyntaxShape, Type, Value,
PipelineData, ShellError, Signature, Span, Spanned, SyntaxShape, Type, Value,
};
#[derive(Clone)]
@ -45,9 +45,7 @@ fn split_row(
let name_span = call.head;
let separator: Spanned<String> = call.req(engine_state, stack, 0)?;
Ok(input
.flat_map(move |x| split_row_helper(&x, &separator, name_span))
.into_pipeline_data())
input.flat_map(move |x| split_row_helper(&x, &separator, name_span))
}
fn split_row_helper(v: &Value, separator: &Spanned<String>, name: Span) -> Vec<Value> {