diff --git a/crates/nu-command/src/commands/ansi/command.rs b/crates/nu-command/src/commands/ansi/command.rs index 15a49cab0a..059688c4c4 100644 --- a/crates/nu-command/src/commands/ansi/command.rs +++ b/crates/nu-command/src/commands/ansi/command.rs @@ -2,7 +2,7 @@ use crate::prelude::*; use nu_ansi_term::*; use nu_engine::WholeStreamCommand; use nu_errors::ShellError; -use nu_protocol::{ReturnSuccess, Signature, SyntaxShape, UntaggedValue, Value}; +use nu_protocol::{Signature, SyntaxShape, UntaggedValue, Value}; use nu_source::Tagged; pub struct Command; @@ -112,7 +112,7 @@ Format: # ] } - fn run_with_actions(&self, args: CommandArgs) -> Result { + fn run(&self, args: CommandArgs) -> Result { let args = args.evaluate_once()?; let code: Option> = args.opt(0)?; @@ -129,9 +129,9 @@ Format: # )); } let output = format!("\x1b[{}", e.item); - return Ok(ActionStream::one(ReturnSuccess::value( + return Ok(OutputStream::one( UntaggedValue::string(output).into_value(e.tag()), - ))); + )); } if let Some(o) = osc { @@ -147,18 +147,18 @@ Format: # //Operating system command aka osc ESC ] <- note the right brace, not left brace for osc // OCS's need to end with a bell '\x07' char let output = format!("\x1b]{};", o.item); - return Ok(ActionStream::one(ReturnSuccess::value( + return Ok(OutputStream::one( UntaggedValue::string(output).into_value(o.tag()), - ))); + )); } if let Some(code) = code { let ansi_code = str_to_ansi(&code.item); if let Some(output) = ansi_code { - Ok(ActionStream::one(ReturnSuccess::value( + Ok(OutputStream::one( UntaggedValue::string(output).into_value(code.tag()), - ))) + )) } else { Err(ShellError::labeled_error( "Unknown ansi code", diff --git a/crates/nu-command/src/commands/ansi/strip.rs b/crates/nu-command/src/commands/ansi/strip.rs index 279288800e..4395126e1f 100644 --- a/crates/nu-command/src/commands/ansi/strip.rs +++ b/crates/nu-command/src/commands/ansi/strip.rs @@ -2,19 +2,12 @@ use crate::prelude::*; use nu_engine::WholeStreamCommand; use nu_errors::ShellError; use nu_protocol::ShellTypeName; -use nu_protocol::{ - ColumnPath, Primitive, ReturnSuccess, Signature, SyntaxShape, UntaggedValue, Value, -}; +use nu_protocol::{Primitive, Signature, SyntaxShape, UntaggedValue, Value}; use nu_source::Tag; use strip_ansi_escapes::strip; pub struct SubCommand; -#[derive(Deserialize)] -struct Arguments { - rest: Vec, -} - impl WholeStreamCommand for SubCommand { fn name(&self) -> &str { "ansi strip" @@ -31,7 +24,7 @@ impl WholeStreamCommand for SubCommand { "strip ansi escape sequences from string" } - fn run_with_actions(&self, args: CommandArgs) -> Result { + fn run(&self, args: CommandArgs) -> Result { operate(args) } @@ -44,14 +37,16 @@ impl WholeStreamCommand for SubCommand { } } -fn operate(args: CommandArgs) -> Result { - let (Arguments { rest }, input) = args.process()?; - let column_paths: Vec<_> = rest; +fn operate(args: CommandArgs) -> Result { + let args = args.evaluate_once()?; - Ok(input + let column_paths: Vec<_> = args.rest_args()?; + + let result: Vec = args + .input .map(move |v| { if column_paths.is_empty() { - ReturnSuccess::value(action(&v, v.tag())?) + action(&v, v.tag()) } else { let mut ret = v; @@ -62,10 +57,12 @@ fn operate(args: CommandArgs) -> Result { )?; } - ReturnSuccess::value(ret) + Ok(ret) } }) - .to_action_stream()) + .collect::, _>>()?; + + Ok(OutputStream::from_stream(result.into_iter())) } fn action(input: &Value, tag: impl Into) -> Result { diff --git a/crates/nu-command/src/commands/benchmark.rs b/crates/nu-command/src/commands/benchmark.rs index 2c5e5d1fc8..493cd239d5 100644 --- a/crates/nu-command/src/commands/benchmark.rs +++ b/crates/nu-command/src/commands/benchmark.rs @@ -50,7 +50,7 @@ impl WholeStreamCommand for Benchmark { "Runs a block and returns the time it took to execute it." } - fn run_with_actions(&self, args: CommandArgs) -> Result { + fn run(&self, args: CommandArgs) -> Result { benchmark(args) } @@ -70,11 +70,16 @@ impl WholeStreamCommand for Benchmark { } } -fn benchmark(args: CommandArgs) -> Result { +fn benchmark(args: CommandArgs) -> Result { let tag = args.call_info.args.span; let mut context = EvaluationContext::from_args(&args); let scope = args.scope().clone(); - let (BenchmarkArgs { block, passthrough }, input) = args.process()?; + + let args = args.evaluate_once()?; + let cmd_args = BenchmarkArgs { + block: args.req(0)?, + passthrough: args.get_flag("passthrough")?, + }; let env = scope.get_env_vars(); let name = generate_free_name(&env); @@ -88,11 +93,12 @@ fn benchmark(args: CommandArgs) -> Result { context.scope.enter_scope(); let result = run_block( - &block.block, + &cmd_args.block.block, &context, - input, + args.input, ExternalRedirection::StdoutAndStderr, ); + context.scope.exit_scope(); let output = result?.into_vec(); @@ -109,7 +115,7 @@ fn benchmark(args: CommandArgs) -> Result { let real_time = into_big_int(end_time - start_time); indexmap.insert("real time".to_string(), real_time); - benchmark_output(indexmap, output, passthrough, &tag, &mut context) + benchmark_output(indexmap, output, cmd_args.passthrough, &tag, &mut context) } // return advanced stats // #[cfg(feature = "rich-benchmark")] @@ -142,10 +148,10 @@ fn benchmark_output( passthrough: Option, tag: T, context: &mut EvaluationContext, -) -> Result +) -> Result where T: Into + Copy, - Output: Into, + Output: Into, { let value = UntaggedValue::Row(Dictionary::from( indexmap @@ -174,7 +180,7 @@ where Ok(block_output.into()) } else { - let benchmark_output = ActionStream::one(value); + let benchmark_output = OutputStream::one(value); Ok(benchmark_output) } }