This commit is contained in:
JT
2021-10-25 19:31:39 +13:00
parent 397a31e69c
commit b5965ee8ef
60 changed files with 502 additions and 455 deletions

View File

@ -1,6 +1,6 @@
use nu_engine::eval_expression;
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EvaluationContext};
use nu_protocol::engine::{Command, EngineState, EvaluationContext, Stack};
use nu_protocol::{
Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, SyntaxShape, Value,
};
@ -44,14 +44,15 @@ impl Command for BuildString {
fn run(
&self,
context: &EvaluationContext,
engine_state: &EngineState,
stack: &mut Stack,
call: &Call,
_input: PipelineData,
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
let output = call
.positional
.iter()
.map(|expr| eval_expression(context, expr).map(|val| val.into_string()))
.map(|expr| eval_expression(engine_state, stack, expr).map(|val| val.into_string()))
.collect::<Result<Vec<String>, ShellError>>()?;
Ok(Value::String {

View File

@ -3,7 +3,7 @@ extern crate unicode_segmentation;
use unicode_segmentation::UnicodeSegmentation;
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EvaluationContext};
use nu_protocol::engine::{Command, EngineState, EvaluationContext, Stack};
use nu_protocol::{
Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, Type, Value,
};
@ -26,11 +26,12 @@ impl Command for Size {
fn run(
&self,
context: &EvaluationContext,
_engine_state: &EngineState,
_stack: &mut Stack,
call: &Call,
input: PipelineData,
) -> Result<PipelineData, ShellError> {
size(context, call, input)
size(call, input)
}
fn examples(&self) -> Vec<Example> {
@ -101,11 +102,7 @@ impl Command for Size {
}
}
fn size(
_context: &EvaluationContext,
call: &Call,
input: PipelineData,
) -> Result<PipelineData, ShellError> {
fn size(call: &Call, input: PipelineData) -> Result<PipelineData, ShellError> {
let span = call.head;
Ok(input
.map(move |v| match v.as_string() {

View File

@ -1,6 +1,6 @@
use nu_protocol::{
ast::Call,
engine::{Command, EvaluationContext},
engine::{Command, EngineState, EvaluationContext, Stack},
Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, Type, Value,
};
@ -39,7 +39,8 @@ impl Command for SubCommand {
fn run(
&self,
_context: &EvaluationContext,
_engine_state: &EngineState,
_stack: &mut Stack,
call: &Call,
input: PipelineData,
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {

View File

@ -1,7 +1,7 @@
use nu_engine::CallExt;
use nu_protocol::{
ast::Call,
engine::{Command, EvaluationContext},
engine::{Command, EngineState, EvaluationContext, Stack},
IntoPipelineData, PipelineData, ShellError, Signature, Span, Spanned, SyntaxShape, Type, Value,
};
@ -34,22 +34,24 @@ impl Command for SubCommand {
fn run(
&self,
context: &EvaluationContext,
engine_state: &EngineState,
stack: &mut Stack,
call: &Call,
input: PipelineData,
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
split_column(context, call, input)
split_column(engine_state, stack, call, input)
}
}
fn split_column(
context: &EvaluationContext,
engine_state: &EngineState,
stack: &mut Stack,
call: &Call,
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 separator: Spanned<String> = call.req(engine_state, stack, 0)?;
let rest: Vec<Spanned<String>> = call.rest(engine_state, stack, 1)?;
let collapse_empty = call.has_flag("collapse-empty");
Ok(input

View File

@ -1,7 +1,7 @@
use nu_engine::get_full_help;
use nu_protocol::{
ast::Call,
engine::{Command, EvaluationContext},
engine::{Command, EngineState, EvaluationContext, Stack},
IntoPipelineData, PipelineData, Signature, Value,
};
@ -23,12 +23,17 @@ impl Command for SplitCommand {
fn run(
&self,
context: &EvaluationContext,
engine_state: &EngineState,
_stack: &mut Stack,
call: &Call,
_input: PipelineData,
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
Ok(Value::String {
val: get_full_help(&SplitCommand.signature(), &SplitCommand.examples(), context),
val: get_full_help(
&SplitCommand.signature(),
&SplitCommand.examples(),
engine_state,
),
span: call.head,
}
.into_pipeline_data())

View File

@ -1,7 +1,7 @@
use nu_engine::CallExt;
use nu_protocol::{
ast::Call,
engine::{Command, EvaluationContext},
engine::{Command, EngineState, EvaluationContext, Stack},
IntoPipelineData, PipelineData, ShellError, Signature, Span, Spanned, SyntaxShape, Type, Value,
};
@ -27,21 +27,23 @@ impl Command for SubCommand {
fn run(
&self,
context: &EvaluationContext,
engine_state: &EngineState,
stack: &mut Stack,
call: &Call,
input: PipelineData,
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
split_row(context, call, input)
split_row(engine_state, stack, call, input)
}
}
fn split_row(
context: &EvaluationContext,
engine_state: &EngineState,
stack: &mut Stack,
call: &Call,
input: PipelineData,
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
let name_span = call.head;
let separator: Spanned<String> = call.req(context, 0)?;
let separator: Spanned<String> = call.req(engine_state, stack, 0)?;
Ok(input
.flat_map(move |x| split_row_helper(&x, &separator, name_span))