mirror of
https://github.com/nushell/nushell.git
synced 2025-08-12 03:31:28 +02:00
WIP
This commit is contained in:
@ -1,9 +1,10 @@
|
||||
use nu_protocol::{
|
||||
ast::Call,
|
||||
engine::{Command, EvaluationContext},
|
||||
Example, ShellError, Signature, Span, Type, Value,
|
||||
Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, Type, Value,
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct SubCommand;
|
||||
|
||||
impl Command for SubCommand {
|
||||
@ -40,16 +41,21 @@ impl Command for SubCommand {
|
||||
&self,
|
||||
_context: &EvaluationContext,
|
||||
call: &Call,
|
||||
input: Value,
|
||||
) -> Result<nu_protocol::Value, nu_protocol::ShellError> {
|
||||
input: PipelineData,
|
||||
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
|
||||
split_chars(call, input)
|
||||
}
|
||||
}
|
||||
|
||||
fn split_chars(call: &Call, input: Value) -> Result<nu_protocol::Value, nu_protocol::ShellError> {
|
||||
fn split_chars(
|
||||
call: &Call,
|
||||
input: PipelineData,
|
||||
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
|
||||
let span = call.head;
|
||||
|
||||
Ok(input.flat_map(span, move |x| split_chars_helper(&x, span)))
|
||||
Ok(input
|
||||
.flat_map(move |x| split_chars_helper(&x, span))
|
||||
.into_pipeline_data())
|
||||
}
|
||||
|
||||
fn split_chars_helper(v: &Value, name: Span) -> Vec<Value> {
|
||||
|
@ -2,9 +2,10 @@ use nu_engine::CallExt;
|
||||
use nu_protocol::{
|
||||
ast::Call,
|
||||
engine::{Command, EvaluationContext},
|
||||
ShellError, Signature, Span, Spanned, SyntaxShape, Type, Value,
|
||||
IntoPipelineData, PipelineData, ShellError, Signature, Span, Spanned, SyntaxShape, Type, Value,
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct SubCommand;
|
||||
|
||||
impl Command for SubCommand {
|
||||
@ -35,8 +36,8 @@ impl Command for SubCommand {
|
||||
&self,
|
||||
context: &EvaluationContext,
|
||||
call: &Call,
|
||||
input: Value,
|
||||
) -> Result<nu_protocol::Value, nu_protocol::ShellError> {
|
||||
input: PipelineData,
|
||||
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
|
||||
split_column(context, call, input)
|
||||
}
|
||||
}
|
||||
@ -44,16 +45,16 @@ impl Command for SubCommand {
|
||||
fn split_column(
|
||||
context: &EvaluationContext,
|
||||
call: &Call,
|
||||
input: Value,
|
||||
) -> Result<nu_protocol::Value, nu_protocol::ShellError> {
|
||||
input: PipelineData,
|
||||
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
|
||||
let name_span = call.head;
|
||||
let separator: Spanned<String> = call.req(context, 0)?;
|
||||
let rest: Vec<Spanned<String>> = call.rest(context, 1)?;
|
||||
let collapse_empty = call.has_flag("collapse-empty");
|
||||
|
||||
input.map(name_span, move |x| {
|
||||
split_column_helper(&x, &separator, &rest, collapse_empty, name_span)
|
||||
})
|
||||
Ok(input
|
||||
.map(move |x| split_column_helper(&x, &separator, &rest, collapse_empty, name_span))
|
||||
.into_pipeline_data())
|
||||
}
|
||||
|
||||
fn split_column_helper(
|
||||
|
@ -2,7 +2,7 @@ use nu_engine::get_full_help;
|
||||
use nu_protocol::{
|
||||
ast::Call,
|
||||
engine::{Command, EvaluationContext},
|
||||
Signature, Value,
|
||||
IntoPipelineData, PipelineData, Signature, Value,
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
@ -25,12 +25,13 @@ impl Command for SplitCommand {
|
||||
&self,
|
||||
context: &EvaluationContext,
|
||||
call: &Call,
|
||||
_input: Value,
|
||||
) -> Result<nu_protocol::Value, nu_protocol::ShellError> {
|
||||
_input: PipelineData,
|
||||
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
|
||||
Ok(Value::String {
|
||||
val: get_full_help(&SplitCommand.signature(), &SplitCommand.examples(), context),
|
||||
span: call.head,
|
||||
})
|
||||
}
|
||||
.into_pipeline_data())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,9 +2,10 @@ use nu_engine::CallExt;
|
||||
use nu_protocol::{
|
||||
ast::Call,
|
||||
engine::{Command, EvaluationContext},
|
||||
ShellError, Signature, Span, Spanned, SyntaxShape, Type, Value,
|
||||
IntoPipelineData, PipelineData, ShellError, Signature, Span, Spanned, SyntaxShape, Type, Value,
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct SubCommand;
|
||||
|
||||
impl Command for SubCommand {
|
||||
@ -28,8 +29,8 @@ impl Command for SubCommand {
|
||||
&self,
|
||||
context: &EvaluationContext,
|
||||
call: &Call,
|
||||
input: Value,
|
||||
) -> Result<nu_protocol::Value, nu_protocol::ShellError> {
|
||||
input: PipelineData,
|
||||
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
|
||||
split_row(context, call, input)
|
||||
}
|
||||
}
|
||||
@ -37,14 +38,14 @@ impl Command for SubCommand {
|
||||
fn split_row(
|
||||
context: &EvaluationContext,
|
||||
call: &Call,
|
||||
input: Value,
|
||||
) -> Result<nu_protocol::Value, nu_protocol::ShellError> {
|
||||
input: PipelineData,
|
||||
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
|
||||
let name_span = call.head;
|
||||
let separator: Spanned<String> = call.req(context, 0)?;
|
||||
|
||||
Ok(input.flat_map(name_span, move |x| {
|
||||
split_row_helper(&x, &separator, name_span)
|
||||
}))
|
||||
Ok(input
|
||||
.flat_map(move |x| split_row_helper(&x, &separator, name_span))
|
||||
.into_pipeline_data())
|
||||
}
|
||||
|
||||
fn split_row_helper(v: &Value, separator: &Spanned<String>, name: Span) -> Vec<Value> {
|
||||
|
Reference in New Issue
Block a user