diff --git a/crates/nu-command/src/commands/config/clear.rs b/crates/nu-command/src/commands/config/clear.rs index 295f48beb8..90e033459f 100644 --- a/crates/nu-command/src/commands/config/clear.rs +++ b/crates/nu-command/src/commands/config/clear.rs @@ -1,7 +1,7 @@ use crate::prelude::*; use nu_engine::WholeStreamCommand; use nu_errors::ShellError; -use nu_protocol::{ReturnSuccess, Signature, UntaggedValue}; +use nu_protocol::{Signature, UntaggedValue}; pub struct SubCommand; @@ -18,7 +18,7 @@ impl WholeStreamCommand for SubCommand { "clear the config" } - fn run_with_actions(&self, args: CommandArgs) -> Result { + fn run(&self, args: CommandArgs) -> Result { clear(args) } @@ -31,22 +31,22 @@ impl WholeStreamCommand for SubCommand { } } -pub fn clear(args: CommandArgs) -> Result { +pub fn clear(args: CommandArgs) -> Result { + let name = args.call_info.name_tag.clone(); let ctx = EvaluationContext::from_args(&args); let result = if let Some(global_cfg) = &mut args.configs().lock().global_config { global_cfg.vars.clear(); global_cfg.write()?; ctx.reload_config(global_cfg)?; - Ok(ActionStream::one(ReturnSuccess::value( - UntaggedValue::Row(global_cfg.vars.clone().into()).into_value(args.call_info.name_tag), - ))) + + let value = UntaggedValue::Row(global_cfg.vars.clone().into()).into_value(name); + Ok(OutputStream::one(value)) } else { - Ok(vec![ReturnSuccess::value(UntaggedValue::Error( - crate::commands::config::err_no_global_cfg_present(), - ))] - .into_iter() - .to_action_stream()) + let value = UntaggedValue::Error(crate::commands::config::err_no_global_cfg_present()) + .into_value(name); + + Ok(OutputStream::one(value)) }; result diff --git a/crates/nu-command/src/commands/config/command.rs b/crates/nu-command/src/commands/config/command.rs index 94d65a5c64..f0faea14bd 100644 --- a/crates/nu-command/src/commands/config/command.rs +++ b/crates/nu-command/src/commands/config/command.rs @@ -2,8 +2,7 @@ use crate::prelude::*; use nu_engine::CommandArgs; use nu_engine::WholeStreamCommand; use nu_errors::ShellError; -use nu_protocol::{ReturnSuccess, Signature, UntaggedValue}; -use nu_stream::ActionStream; +use nu_protocol::{Signature, UntaggedValue}; pub struct Command; @@ -20,22 +19,19 @@ impl WholeStreamCommand for Command { "Configuration management." } - fn run_with_actions(&self, args: CommandArgs) -> Result { + fn run(&self, args: CommandArgs) -> Result { let name = args.call_info.name_tag.clone(); if let Some(global_cfg) = &args.configs().lock().global_config { let result = global_cfg.vars.clone(); - Ok(vec![ReturnSuccess::value( - UntaggedValue::Row(result.into()).into_value(name), - )] - .into_iter() - .to_action_stream()) + let value = UntaggedValue::Row(result.into()).into_value(name); + + Ok(OutputStream::one(value)) } else { - Ok(vec![ReturnSuccess::value(UntaggedValue::Error( - crate::commands::config::err_no_global_cfg_present(), - ))] - .into_iter() - .to_action_stream()) + let value = UntaggedValue::Error(crate::commands::config::err_no_global_cfg_present()) + .into_value(name); + + Ok(OutputStream::one(value)) } } } diff --git a/crates/nu-command/src/commands/config/get.rs b/crates/nu-command/src/commands/config/get.rs index 3d07c81c3e..367bcff0a8 100644 --- a/crates/nu-command/src/commands/config/get.rs +++ b/crates/nu-command/src/commands/config/get.rs @@ -1,15 +1,10 @@ use crate::prelude::*; use nu_engine::WholeStreamCommand; use nu_errors::ShellError; -use nu_protocol::{ColumnPath, ReturnSuccess, Signature, SyntaxShape, UntaggedValue, Value}; +use nu_protocol::{Signature, SyntaxShape, UntaggedValue, Value}; pub struct SubCommand; -#[derive(Deserialize)] -pub struct Arguments { - column_path: ColumnPath, -} - impl WholeStreamCommand for SubCommand { fn name(&self) -> &str { "config get" @@ -27,7 +22,7 @@ impl WholeStreamCommand for SubCommand { "Gets a value from the config" } - fn run_with_actions(&self, args: CommandArgs) -> Result { + fn run(&self, args: CommandArgs) -> Result { get(args) } @@ -40,11 +35,12 @@ impl WholeStreamCommand for SubCommand { } } -pub fn get(args: CommandArgs) -> Result { +pub fn get(args: CommandArgs) -> Result { let name = args.call_info.name_tag.clone(); let ctx = EvaluationContext::from_args(&args); + let args = args.evaluate_once()?; - let (Arguments { column_path }, _) = args.process()?; + let column_path = args.req(0)?; let result = if let Some(global_cfg) = &ctx.configs.lock().global_config { let result = UntaggedValue::row(global_cfg.vars.clone()).into_value(&name); @@ -53,15 +49,14 @@ pub fn get(args: CommandArgs) -> Result { Value { value: UntaggedValue::Table(list), .. - } => list.into_iter().to_action_stream(), - x => ActionStream::one(ReturnSuccess::value(x)), + } => OutputStream::from_stream(list.into_iter()), + x => OutputStream::one(x), }) } else { - Ok(vec![ReturnSuccess::value(UntaggedValue::Error( - crate::commands::config::err_no_global_cfg_present(), - ))] - .into_iter() - .to_action_stream()) + let value = UntaggedValue::Error(crate::commands::config::err_no_global_cfg_present()) + .into_value(name); + + Ok(OutputStream::one(value)) }; result diff --git a/crates/nu-command/src/commands/config/path.rs b/crates/nu-command/src/commands/config/path.rs index 3a469f6c5f..4e32596cc8 100644 --- a/crates/nu-command/src/commands/config/path.rs +++ b/crates/nu-command/src/commands/config/path.rs @@ -1,7 +1,7 @@ use crate::prelude::*; use nu_engine::WholeStreamCommand; use nu_errors::ShellError; -use nu_protocol::{Primitive, ReturnSuccess, Signature, UntaggedValue}; +use nu_protocol::{Primitive, Signature, UntaggedValue}; pub struct SubCommand; @@ -18,7 +18,7 @@ impl WholeStreamCommand for SubCommand { "return the path to the config file" } - fn run_with_actions(&self, args: CommandArgs) -> Result { + fn run(&self, args: CommandArgs) -> Result { path(args) } @@ -31,16 +31,18 @@ impl WholeStreamCommand for SubCommand { } } -pub fn path(args: CommandArgs) -> Result { +pub fn path(args: CommandArgs) -> Result { + let name = args.call_info.name_tag.clone(); + if let Some(global_cfg) = &mut args.configs().lock().global_config { - Ok(ActionStream::one(ReturnSuccess::value( - UntaggedValue::Primitive(Primitive::FilePath(global_cfg.file_path.clone())), - ))) + let value = UntaggedValue::Primitive(Primitive::FilePath(global_cfg.file_path.clone())) + .into_value(name); + + Ok(OutputStream::one(value)) } else { - Ok(vec![ReturnSuccess::value(UntaggedValue::Error( - crate::commands::config::err_no_global_cfg_present(), - ))] - .into_iter() - .to_action_stream()) + let value = UntaggedValue::Error(crate::commands::config::err_no_global_cfg_present()) + .into_value(name); + + Ok(OutputStream::one(value)) } } diff --git a/crates/nu-command/src/commands/config/remove.rs b/crates/nu-command/src/commands/config/remove.rs index c8ecb4c1bb..9c3823aac2 100644 --- a/crates/nu-command/src/commands/config/remove.rs +++ b/crates/nu-command/src/commands/config/remove.rs @@ -1,16 +1,11 @@ use crate::prelude::*; use nu_engine::WholeStreamCommand; use nu_errors::ShellError; -use nu_protocol::{ReturnSuccess, Signature, SyntaxShape, UntaggedValue}; +use nu_protocol::{Signature, SyntaxShape, UntaggedValue, Value}; use nu_source::Tagged; pub struct SubCommand; -#[derive(Deserialize)] -pub struct Arguments { - remove: Tagged, -} - impl WholeStreamCommand for SubCommand { fn name(&self) -> &str { "config remove" @@ -28,7 +23,7 @@ impl WholeStreamCommand for SubCommand { "Removes a value from the config" } - fn run_with_actions(&self, args: CommandArgs) -> Result { + fn run(&self, args: CommandArgs) -> Result { remove(args) } @@ -41,9 +36,11 @@ impl WholeStreamCommand for SubCommand { } } -pub fn remove(args: CommandArgs) -> Result { +pub fn remove(args: CommandArgs) -> Result { + let name = args.call_info.name_tag.clone(); let ctx = EvaluationContext::from_args(&args); - let (Arguments { remove }, _) = args.process()?; + let args = args.evaluate_once()?; + let remove: Tagged = args.req(0)?; let key = remove.to_string(); @@ -52,11 +49,10 @@ pub fn remove(args: CommandArgs) -> Result { global_cfg.vars.swap_remove(&key); global_cfg.write()?; ctx.reload_config(global_cfg)?; - Ok(vec![ReturnSuccess::value( - UntaggedValue::row(global_cfg.vars.clone()).into_value(remove.tag()), - )] - .into_iter() - .to_action_stream()) + + let value: Value = UntaggedValue::row(global_cfg.vars.clone()).into_value(remove.tag); + + Ok(OutputStream::one(value)) } else { Err(ShellError::labeled_error( "Key does not exist in config", @@ -65,11 +61,10 @@ pub fn remove(args: CommandArgs) -> Result { )) } } else { - Ok(vec![ReturnSuccess::value(UntaggedValue::Error( - crate::commands::config::err_no_global_cfg_present(), - ))] - .into_iter() - .to_action_stream()) + let value = UntaggedValue::Error(crate::commands::config::err_no_global_cfg_present()) + .into_value(name); + + Ok(OutputStream::one(value)) }; result diff --git a/crates/nu-command/src/commands/config/set.rs b/crates/nu-command/src/commands/config/set.rs index cdb4c97f25..289f17d87a 100644 --- a/crates/nu-command/src/commands/config/set.rs +++ b/crates/nu-command/src/commands/config/set.rs @@ -1,16 +1,10 @@ use crate::prelude::*; use nu_engine::WholeStreamCommand; use nu_errors::ShellError; -use nu_protocol::{ColumnPath, ReturnSuccess, Signature, SyntaxShape, UntaggedValue, Value}; +use nu_protocol::{Signature, SyntaxShape, UntaggedValue, Value}; pub struct SubCommand; -#[derive(Deserialize)] -pub struct Arguments { - column_path: ColumnPath, - value: Value, -} - impl WholeStreamCommand for SubCommand { fn name(&self) -> &str { "config set" @@ -26,7 +20,7 @@ impl WholeStreamCommand for SubCommand { "Sets a value in the config" } - fn run_with_actions(&self, args: CommandArgs) -> Result { + fn run(&self, args: CommandArgs) -> Result { set(args) } @@ -56,16 +50,13 @@ impl WholeStreamCommand for SubCommand { } } -pub fn set(args: CommandArgs) -> Result { +pub fn set(args: CommandArgs) -> Result { let name = args.call_info.name_tag.clone(); let ctx = EvaluationContext::from_args(&args); - let ( - Arguments { - column_path, - mut value, - }, - _, - ) = args.process()?; + let args = args.evaluate_once()?; + + let column_path = args.req(0)?; + let mut value: Value = args.req(1)?; let result = if let Some(global_cfg) = &mut ctx.configs.lock().global_config { let configuration = UntaggedValue::row(global_cfg.vars.clone()).into_value(&name); @@ -85,19 +76,17 @@ pub fn set(args: CommandArgs) -> Result { global_cfg.write()?; ctx.reload_config(global_cfg)?; - Ok(ActionStream::one(ReturnSuccess::value( - UntaggedValue::row(global_cfg.vars.clone()).into_value(name), - ))) + let value = UntaggedValue::row(global_cfg.vars.clone()).into_value(name); + Ok(OutputStream::one(value)) } - Ok(_) => Ok(ActionStream::empty()), + Ok(_) => Ok(OutputStream::empty()), Err(reason) => Err(reason), } } else { - Ok(vec![ReturnSuccess::value(UntaggedValue::Error( - crate::commands::config::err_no_global_cfg_present(), - ))] - .into_iter() - .to_action_stream()) + let value = UntaggedValue::Error(crate::commands::config::err_no_global_cfg_present()) + .into_value(name); + + Ok(OutputStream::one(value)) }; result diff --git a/crates/nu-command/src/commands/config/set_into.rs b/crates/nu-command/src/commands/config/set_into.rs index f0ac375691..a5b765da69 100644 --- a/crates/nu-command/src/commands/config/set_into.rs +++ b/crates/nu-command/src/commands/config/set_into.rs @@ -1,16 +1,11 @@ use crate::prelude::*; 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 SubCommand; -#[derive(Deserialize)] -pub struct Arguments { - set_into: Tagged, -} - impl WholeStreamCommand for SubCommand { fn name(&self) -> &str { "config set_into" @@ -28,7 +23,7 @@ impl WholeStreamCommand for SubCommand { "Sets a value in the config" } - fn run_with_actions(&self, args: CommandArgs) -> Result { + fn run(&self, args: CommandArgs) -> Result { set_into(args) } @@ -41,20 +36,22 @@ impl WholeStreamCommand for SubCommand { } } -pub fn set_into(args: CommandArgs) -> Result { +pub fn set_into(args: CommandArgs) -> Result { let name = args.call_info.name_tag.clone(); let ctx = EvaluationContext::from_args(&args); - let (Arguments { set_into: v }, input) = args.process()?; + let args = args.evaluate_once()?; - let rows: Vec = input.collect(); - let key = v.to_string(); + let set_into: Tagged = args.req(0)?; + + let rows: Vec = args.input.collect(); + let key = set_into.to_string(); let result = if let Some(global_cfg) = &mut ctx.configs.lock().global_config { if rows.is_empty() { return Err(ShellError::labeled_error( "No values given for set_into", "needs value(s) from pipeline", - v.tag(), + set_into.tag(), )); } else if rows.len() == 1 { // A single value @@ -71,15 +68,14 @@ pub fn set_into(args: CommandArgs) -> Result { global_cfg.write()?; ctx.reload_config(global_cfg)?; - Ok(ActionStream::one(ReturnSuccess::value( - UntaggedValue::row(global_cfg.vars.clone()).into_value(name), - ))) + let value = UntaggedValue::row(global_cfg.vars.clone()).into_value(name); + + Ok(OutputStream::one(value)) } else { - Ok(vec![ReturnSuccess::value(UntaggedValue::Error( - crate::commands::config::err_no_global_cfg_present(), - ))] - .into_iter() - .to_action_stream()) + let value = UntaggedValue::Error(crate::commands::config::err_no_global_cfg_present()) + .into_value(name); + + Ok(OutputStream::one(value)) }; result