Split OutputStream into ActionStream/OutputStream (#3304)

* Split OutputStream into ActionStream/OutputStream

* Fmt

* Missed update

* Cleanup helper names

* Fmt
This commit is contained in:
Jonathan Turner 2021-04-12 14:35:01 +12:00 committed by GitHub
parent dbecbdccd4
commit 5f550a355b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
250 changed files with 1006 additions and 926 deletions

View file

@ -30,7 +30,7 @@ pub use nu_data::config;
pub use nu_data::dict::TaggedListBuilder;
pub use nu_data::primitive;
pub use nu_data::value;
pub use nu_stream::{InputStream, InterruptibleStream, OutputStream};
pub use nu_stream::{ActionStream, InputStream, InterruptibleStream};
pub use nu_value_ext::ValueExt;
pub use num_traits::cast::ToPrimitive;

View file

@ -36,7 +36,7 @@ pub(crate) use nu_engine::Host;
pub(crate) use nu_errors::ShellError;
#[allow(unused_imports)]
pub(crate) use nu_protocol::outln;
pub(crate) use nu_stream::OutputStream;
pub(crate) use nu_stream::ActionStream;
#[allow(unused_imports)]
pub(crate) use nu_value_ext::ValueExt;
#[allow(unused_imports)]
@ -44,33 +44,16 @@ pub(crate) use std::sync::atomic::Ordering;
#[allow(clippy::clippy::wrong_self_convention)]
pub trait FromInputStream {
fn from_input_stream(self) -> OutputStream;
fn from_input_stream(self) -> ActionStream;
}
impl<T> FromInputStream for T
where
T: Iterator<Item = nu_protocol::Value> + Send + Sync + 'static,
{
fn from_input_stream(self) -> OutputStream {
OutputStream {
fn from_input_stream(self) -> ActionStream {
ActionStream {
values: Box::new(self.map(nu_protocol::ReturnSuccess::value)),
}
}
}
#[allow(clippy::clippy::wrong_self_convention)]
pub trait ToOutputStream {
fn to_output_stream(self) -> OutputStream;
}
impl<T, U> ToOutputStream for T
where
T: Iterator<Item = U> + Send + Sync + 'static,
U: Into<nu_protocol::ReturnValue>,
{
fn to_output_stream(self) -> OutputStream {
OutputStream {
values: Box::new(self.map(|item| item.into())),
}
}
}

View file

@ -5,6 +5,7 @@ use nu_errors::ShellError;
use nu_protocol::{
hir::CapturedBlock, hir::ClassifiedCommand, Signature, SyntaxShape, UntaggedValue,
};
use nu_stream::ToActionStream;
pub struct Command;
@ -30,7 +31,7 @@ impl WholeStreamCommand for Command {
"Find if the table rows matches the condition."
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
all(args)
}
@ -52,7 +53,7 @@ impl WholeStreamCommand for Command {
}
}
fn all(args: CommandArgs) -> Result<OutputStream, ShellError> {
fn all(args: CommandArgs) -> Result<ActionStream, ShellError> {
let ctx = Arc::new(EvaluationContext::from_args(&args));
let tag = args.call_info.name_tag.clone();
let (Arguments { block }, input) = args.process()?;
@ -117,7 +118,7 @@ fn all(args: CommandArgs) -> Result<OutputStream, ShellError> {
Err(e) => Err(e),
}
})?
.to_output_stream())
.to_action_stream())
}
#[cfg(test)]

View file

@ -112,7 +112,7 @@ Format: #
]
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
let args = args.evaluate_once()?;
let code: Option<Result<Tagged<String>, ShellError>> = args.opt(0);
@ -130,7 +130,7 @@ Format: #
));
}
let output = format!("\x1b[{}", e.item);
return Ok(OutputStream::one(ReturnSuccess::value(
return Ok(ActionStream::one(ReturnSuccess::value(
UntaggedValue::string(output).into_value(e.tag()),
)));
}
@ -149,7 +149,7 @@ 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(OutputStream::one(ReturnSuccess::value(
return Ok(ActionStream::one(ReturnSuccess::value(
UntaggedValue::string(output).into_value(o.tag()),
)));
}
@ -159,7 +159,7 @@ Format: #
let ansi_code = str_to_ansi(&code.item);
if let Some(output) = ansi_code {
Ok(OutputStream::one(ReturnSuccess::value(
Ok(ActionStream::one(ReturnSuccess::value(
UntaggedValue::string(output).into_value(code.tag()),
)))
} else {

View file

@ -31,7 +31,7 @@ impl WholeStreamCommand for SubCommand {
"strip ansi escape sequences from string"
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
operate(args)
}
@ -44,7 +44,7 @@ impl WholeStreamCommand for SubCommand {
}
}
fn operate(args: CommandArgs) -> Result<OutputStream, ShellError> {
fn operate(args: CommandArgs) -> Result<ActionStream, ShellError> {
let (Arguments { rest }, input) = args.process()?;
let column_paths: Vec<_> = rest;
@ -65,7 +65,7 @@ fn operate(args: CommandArgs) -> Result<OutputStream, ShellError> {
ReturnSuccess::value(ret)
}
})
.to_output_stream())
.to_action_stream())
}
fn action(input: &Value, tag: impl Into<Tag>) -> Result<Value, ShellError> {

View file

@ -30,7 +30,7 @@ impl WholeStreamCommand for Command {
"Find if the table rows matches the condition."
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
any(args)
}
@ -52,7 +52,7 @@ impl WholeStreamCommand for Command {
}
}
fn any(args: CommandArgs) -> Result<OutputStream, ShellError> {
fn any(args: CommandArgs) -> Result<ActionStream, ShellError> {
let ctx = Arc::new(EvaluationContext::from_args(&args));
let tag = args.call_info.name_tag.clone();
let (Arguments { block }, input) = args.process()?;
@ -117,7 +117,7 @@ fn any(args: CommandArgs) -> Result<OutputStream, ShellError> {
Err(e) => Err(e),
}
})?
.to_output_stream())
.to_action_stream())
}
#[cfg(test)]

View file

@ -27,7 +27,7 @@ impl WholeStreamCommand for Command {
"Append a row to the table."
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
let (Arguments { mut value }, input) = args.process()?;
let input: Vec<Value> = input.collect();
@ -51,7 +51,7 @@ impl WholeStreamCommand for Command {
.into_iter()
.chain(vec![value])
.map(ReturnSuccess::value)
.to_output_stream())
.to_action_stream())
}
fn examples(&self) -> Vec<Example> {

View file

@ -25,8 +25,8 @@ The .nu-env file has the same format as your $HOME/nu/config.toml file. By loadi
fn signature(&self) -> Signature {
Signature::build("autoenv")
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
Ok(OutputStream::one(ReturnSuccess::value(
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
Ok(ActionStream::one(ReturnSuccess::value(
UntaggedValue::string(get_full_help(&Autoenv, &args.scope)).into_value(Tag::unknown()),
)))
}

View file

@ -21,7 +21,7 @@ impl WholeStreamCommand for AutoenvTrust {
"Trust a .nu-env file in the current or given directory"
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
let tag = args.call_info.name_tag.clone();
let ctx = EvaluationContext::from_args(&args);
@ -55,7 +55,7 @@ impl WholeStreamCommand for AutoenvTrust {
})?;
fs::write(config_path, tomlstr).expect("Couldn't write to toml file");
Ok(OutputStream::one(ReturnSuccess::value(
Ok(ActionStream::one(ReturnSuccess::value(
UntaggedValue::string(".nu-env trusted!").into_value(tag),
)))
}

View file

@ -25,7 +25,7 @@ impl WholeStreamCommand for AutoenvUnTrust {
"Untrust a .nu-env file in the current or given directory"
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
let tag = args.call_info.name_tag.clone();
let ctx = EvaluationContext::from_args(&args);
let file_to_untrust = match args.call_info.evaluate(&ctx)?.args.nth(0) {
@ -79,7 +79,7 @@ impl WholeStreamCommand for AutoenvUnTrust {
})?;
fs::write(config_path, tomlstr).expect("Couldn't write to toml file");
Ok(OutputStream::one(ReturnSuccess::value(
Ok(ActionStream::one(ReturnSuccess::value(
UntaggedValue::string(".nu-env untrusted!").into_value(tag),
)))
}

View file

@ -80,7 +80,7 @@ pub fn autoview(context: CommandArgs) -> Result<OutputStream, ShellError> {
);
let command_args =
create_default_command_args(&context).with_input(stream);
let result = text.run(command_args)?;
let result = text.run_with_actions(command_args)?;
let _ = result.collect::<Vec<_>>();
} else {
out!("{}", s);
@ -162,7 +162,7 @@ pub fn autoview(context: CommandArgs) -> Result<OutputStream, ShellError> {
stream.push_back(x);
let command_args =
create_default_command_args(&context).with_input(stream);
let result = binary.run(command_args)?;
let result = binary.run_with_actions(command_args)?;
let _ = result.collect::<Vec<_>>();
} else {
use pretty_hex::*;
@ -255,7 +255,7 @@ pub fn autoview(context: CommandArgs) -> Result<OutputStream, ShellError> {
}
}
Ok(OutputStream::empty())
Ok(InputStream::empty())
}
fn create_default_command_args(context: &RunnableContextWithoutInput) -> RawCommandArgs {

View file

@ -47,7 +47,7 @@ impl WholeStreamCommand for Benchmark {
"Runs a block and returns the time it took to execute it."
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
benchmark(args)
}
@ -67,7 +67,7 @@ impl WholeStreamCommand for Benchmark {
}
}
fn benchmark(raw_args: CommandArgs) -> Result<OutputStream, ShellError> {
fn benchmark(raw_args: CommandArgs) -> Result<ActionStream, ShellError> {
let tag = raw_args.call_info.args.span;
let mut context = EvaluationContext::from_args(&raw_args);
let scope = raw_args.scope.clone();
@ -134,10 +134,10 @@ fn benchmark_output<T, Output>(
passthrough: Option<CapturedBlock>,
tag: T,
context: &mut EvaluationContext,
) -> Result<OutputStream, ShellError>
) -> Result<ActionStream, ShellError>
where
T: Into<Tag> + Copy,
Output: Into<OutputStream>,
Output: Into<ActionStream>,
{
let value = UntaggedValue::Row(Dictionary::from(
indexmap
@ -161,7 +161,7 @@ where
Ok(block_output.into())
} else {
let benchmark_output = OutputStream::one(value);
let benchmark_output = ActionStream::one(value);
Ok(benchmark_output)
}
}

View file

@ -21,7 +21,7 @@ impl WholeStreamCommand for BuildString {
"Builds a string from the arguments."
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
let tag = args.call_info.name_tag.clone();
let args = args.evaluate_once()?;
let rest: Vec<Value> = args.rest(0)?;
@ -32,7 +32,7 @@ impl WholeStreamCommand for BuildString {
output_string.push_str(&format_leaf(&r).plain_string(100_000))
}
Ok(OutputStream::one(ReturnSuccess::value(
Ok(ActionStream::one(ReturnSuccess::value(
UntaggedValue::string(output_string).into_value(tag),
)))
}

View file

@ -40,7 +40,7 @@ impl WholeStreamCommand for Cal {
"Display a calendar."
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
cal(args)
}
@ -65,7 +65,7 @@ impl WholeStreamCommand for Cal {
}
}
pub fn cal(args: CommandArgs) -> Result<OutputStream, ShellError> {
pub fn cal(args: CommandArgs) -> Result<ActionStream, ShellError> {
let args = args.evaluate_once()?;
let mut calendar_vec_deque = VecDeque::new();
let tag = args.call_info.name_tag.clone();
@ -101,7 +101,7 @@ pub fn cal(args: CommandArgs) -> Result<OutputStream, ShellError> {
current_day_option,
)?;
Ok(calendar_vec_deque.into_iter().to_output_stream())
Ok(calendar_vec_deque.into_iter().to_action_stream())
}
fn get_invalid_year_shell_error(year_tag: &Tag) -> ShellError {

View file

@ -24,7 +24,7 @@ impl WholeStreamCommand for Cd {
"Change to a new path."
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
let name = args.call_info.name_tag.clone();
let shell_manager = args.shell_manager.clone();
let (args, _): (CdArgs, _) = args.process()?;

View file

@ -57,7 +57,7 @@ impl WholeStreamCommand for Char {
]
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
let args = args.evaluate_once()?;
let name: Tagged<String> = args.req(0)?;
@ -83,13 +83,13 @@ impl WholeStreamCommand for Char {
Err(e) => return Err(e),
}
}
Ok(OutputStream::one(ReturnSuccess::value(
Ok(ActionStream::one(ReturnSuccess::value(
UntaggedValue::string(multi_byte).into_value(name.tag),
)))
} else {
let decoded_char = string_to_unicode_char(&name.item, &name.tag);
if let Ok(ch) = decoded_char {
Ok(OutputStream::one(ReturnSuccess::value(
Ok(ActionStream::one(ReturnSuccess::value(
UntaggedValue::string(ch).into_value(name.tag()),
)))
} else {
@ -103,7 +103,7 @@ impl WholeStreamCommand for Char {
} else {
let special_character = str_to_character(&name.item);
if let Some(output) = special_character {
Ok(OutputStream::one(ReturnSuccess::value(
Ok(ActionStream::one(ReturnSuccess::value(
UntaggedValue::string(output).into_value(name.tag()),
)))
} else {

View file

@ -19,14 +19,14 @@ impl WholeStreamCommand for Chart {
"Displays charts."
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
if args.scope.get_command("chart bar").is_none() {
return Err(ShellError::untagged_runtime_error(
"nu_plugin_chart not installed.",
));
}
Ok(OutputStream::one(Ok(ReturnSuccess::Value(
Ok(ActionStream::one(Ok(ReturnSuccess::Value(
UntaggedValue::string(get_full_help(&Chart, &args.scope)).into_value(Tag::unknown()),
))))
}

View file

@ -19,7 +19,7 @@ impl WholeStreamCommand for Clear {
"Clears the terminal."
}
fn run(&self, _: CommandArgs) -> Result<OutputStream, ShellError> {
fn run(&self, _: CommandArgs) -> Result<InputStream, ShellError> {
if cfg!(windows) {
Command::new("cmd")
.args(&["/C", "cls"])
@ -31,7 +31,7 @@ impl WholeStreamCommand for Clear {
.status()
.expect("failed to execute process");
}
Ok(OutputStream::empty())
Ok(InputStream::empty())
}
fn examples(&self) -> Vec<Example> {

View file

@ -21,7 +21,7 @@ impl WholeStreamCommand for Clip {
"Copy the contents of the pipeline to the copy/paste buffer."
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
clip(args)
}
@ -41,9 +41,9 @@ impl WholeStreamCommand for Clip {
}
}
pub fn clip(args: CommandArgs) -> Result<OutputStream, ShellError> {
pub fn clip(args: CommandArgs) -> Result<ActionStream, ShellError> {
let input = args.input;
let name = args.call_info.name_tag.clone();
let name = args.call_info.name_tag;
let values: Vec<Value> = input.collect();
if let Ok(mut clip_context) = Clipboard::new() {
@ -88,7 +88,7 @@ pub fn clip(args: CommandArgs) -> Result<OutputStream, ShellError> {
name,
));
}
Ok(OutputStream::empty())
Ok(ActionStream::empty())
}
#[cfg(test)]

View file

@ -25,7 +25,7 @@ impl WholeStreamCommand for Compact {
"Creates a table with non-empty rows."
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
compact(args)
}
@ -38,7 +38,7 @@ impl WholeStreamCommand for Compact {
}
}
pub fn compact(args: CommandArgs) -> Result<OutputStream, ShellError> {
pub fn compact(args: CommandArgs) -> Result<ActionStream, ShellError> {
let (CompactArgs { rest: columns }, input) = args.process()?;
Ok(input
.filter_map(move |item| {
@ -67,7 +67,7 @@ pub fn compact(args: CommandArgs) -> Result<OutputStream, ShellError> {
}
}
})
.to_output_stream())
.to_action_stream())
}
#[cfg(test)]

View file

@ -18,7 +18,7 @@ impl WholeStreamCommand for SubCommand {
"clear the config"
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
clear(args)
}
@ -31,14 +31,14 @@ impl WholeStreamCommand for SubCommand {
}
}
pub fn clear(args: CommandArgs) -> Result<OutputStream, ShellError> {
pub fn clear(args: CommandArgs) -> Result<ActionStream, ShellError> {
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(OutputStream::one(ReturnSuccess::value(
Ok(ActionStream::one(ReturnSuccess::value(
UntaggedValue::Row(global_cfg.vars.clone().into()).into_value(args.call_info.name_tag),
)))
} else {
@ -46,7 +46,7 @@ pub fn clear(args: CommandArgs) -> Result<OutputStream, ShellError> {
crate::commands::config::err_no_global_cfg_present(),
))]
.into_iter()
.to_output_stream())
.to_action_stream())
};
result

View file

@ -3,7 +3,7 @@ use nu_engine::CommandArgs;
use nu_engine::WholeStreamCommand;
use nu_errors::ShellError;
use nu_protocol::{ReturnSuccess, Signature, UntaggedValue};
use nu_stream::OutputStream;
use nu_stream::ActionStream;
pub struct Command;
@ -20,7 +20,7 @@ impl WholeStreamCommand for Command {
"Configuration management."
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
let name = args.call_info.name_tag;
if let Some(global_cfg) = &args.configs.lock().global_config {
@ -29,13 +29,13 @@ impl WholeStreamCommand for Command {
UntaggedValue::Row(result.into()).into_value(name),
)]
.into_iter()
.to_output_stream())
.to_action_stream())
} else {
Ok(vec![ReturnSuccess::value(UntaggedValue::Error(
crate::commands::config::err_no_global_cfg_present(),
))]
.into_iter()
.to_output_stream())
.to_action_stream())
}
}
}

View file

@ -27,7 +27,7 @@ impl WholeStreamCommand for SubCommand {
"Gets a value from the config"
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
get(args)
}
@ -40,7 +40,7 @@ impl WholeStreamCommand for SubCommand {
}
}
pub fn get(args: CommandArgs) -> Result<OutputStream, ShellError> {
pub fn get(args: CommandArgs) -> Result<ActionStream, ShellError> {
let name = args.call_info.name_tag.clone();
let ctx = EvaluationContext::from_args(&args);
@ -53,15 +53,15 @@ pub fn get(args: CommandArgs) -> Result<OutputStream, ShellError> {
Value {
value: UntaggedValue::Table(list),
..
} => list.into_iter().to_output_stream(),
x => OutputStream::one(ReturnSuccess::value(x)),
} => list.into_iter().to_action_stream(),
x => ActionStream::one(ReturnSuccess::value(x)),
})
} else {
Ok(vec![ReturnSuccess::value(UntaggedValue::Error(
crate::commands::config::err_no_global_cfg_present(),
))]
.into_iter()
.to_output_stream())
.to_action_stream())
};
result

View file

@ -18,7 +18,7 @@ impl WholeStreamCommand for SubCommand {
"return the path to the config file"
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
path(args)
}
@ -31,9 +31,9 @@ impl WholeStreamCommand for SubCommand {
}
}
pub fn path(args: CommandArgs) -> Result<OutputStream, ShellError> {
pub fn path(args: CommandArgs) -> Result<ActionStream, ShellError> {
if let Some(global_cfg) = &mut args.configs.lock().global_config {
Ok(OutputStream::one(ReturnSuccess::value(
Ok(ActionStream::one(ReturnSuccess::value(
UntaggedValue::Primitive(Primitive::FilePath(global_cfg.file_path.clone())),
)))
} else {
@ -41,6 +41,6 @@ pub fn path(args: CommandArgs) -> Result<OutputStream, ShellError> {
crate::commands::config::err_no_global_cfg_present(),
))]
.into_iter()
.to_output_stream())
.to_action_stream())
}
}

View file

@ -28,7 +28,7 @@ impl WholeStreamCommand for SubCommand {
"Removes a value from the config"
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
remove(args)
}
@ -41,7 +41,7 @@ impl WholeStreamCommand for SubCommand {
}
}
pub fn remove(args: CommandArgs) -> Result<OutputStream, ShellError> {
pub fn remove(args: CommandArgs) -> Result<ActionStream, ShellError> {
let ctx = EvaluationContext::from_args(&args);
let (Arguments { remove }, _) = args.process()?;
@ -56,7 +56,7 @@ pub fn remove(args: CommandArgs) -> Result<OutputStream, ShellError> {
UntaggedValue::row(global_cfg.vars.clone()).into_value(remove.tag()),
)]
.into_iter()
.to_output_stream())
.to_action_stream())
} else {
Err(ShellError::labeled_error(
"Key does not exist in config",
@ -69,7 +69,7 @@ pub fn remove(args: CommandArgs) -> Result<OutputStream, ShellError> {
crate::commands::config::err_no_global_cfg_present(),
))]
.into_iter()
.to_output_stream())
.to_action_stream())
};
result

View file

@ -26,7 +26,7 @@ impl WholeStreamCommand for SubCommand {
"Sets a value in the config"
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
set(args)
}
@ -56,7 +56,7 @@ impl WholeStreamCommand for SubCommand {
}
}
pub fn set(args: CommandArgs) -> Result<OutputStream, ShellError> {
pub fn set(args: CommandArgs) -> Result<ActionStream, ShellError> {
let name = args.call_info.name_tag.clone();
let ctx = EvaluationContext::from_args(&args);
let (
@ -85,11 +85,11 @@ pub fn set(args: CommandArgs) -> Result<OutputStream, ShellError> {
global_cfg.write()?;
ctx.reload_config(global_cfg)?;
Ok(OutputStream::one(ReturnSuccess::value(
Ok(ActionStream::one(ReturnSuccess::value(
UntaggedValue::row(global_cfg.vars.clone()).into_value(name),
)))
}
Ok(_) => Ok(OutputStream::empty()),
Ok(_) => Ok(ActionStream::empty()),
Err(reason) => Err(reason),
}
} else {
@ -97,7 +97,7 @@ pub fn set(args: CommandArgs) -> Result<OutputStream, ShellError> {
crate::commands::config::err_no_global_cfg_present(),
))]
.into_iter()
.to_output_stream())
.to_action_stream())
};
result

View file

@ -28,7 +28,7 @@ impl WholeStreamCommand for SubCommand {
"Sets a value in the config"
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
set_into(args)
}
@ -41,7 +41,7 @@ impl WholeStreamCommand for SubCommand {
}
}
pub fn set_into(args: CommandArgs) -> Result<OutputStream, ShellError> {
pub fn set_into(args: CommandArgs) -> Result<ActionStream, ShellError> {
let name = args.call_info.name_tag.clone();
let ctx = EvaluationContext::from_args(&args);
let (Arguments { set_into: v }, input) = args.process()?;
@ -71,7 +71,7 @@ pub fn set_into(args: CommandArgs) -> Result<OutputStream, ShellError> {
global_cfg.write()?;
ctx.reload_config(global_cfg)?;
Ok(OutputStream::one(ReturnSuccess::value(
Ok(ActionStream::one(ReturnSuccess::value(
UntaggedValue::row(global_cfg.vars.clone()).into_value(name),
)))
} else {
@ -79,7 +79,7 @@ pub fn set_into(args: CommandArgs) -> Result<OutputStream, ShellError> {
crate::commands::config::err_no_global_cfg_present(),
))]
.into_iter()
.to_output_stream())
.to_action_stream())
};
result

View file

@ -25,7 +25,7 @@ impl WholeStreamCommand for Cpy {
"Copy files."
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
let shell_manager = args.shell_manager.clone();
let name = args.call_info.name_tag.clone();
let (args, _) = args.process()?;

View file

@ -18,8 +18,8 @@ impl WholeStreamCommand for Command {
"Apply date function."
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
Ok(OutputStream::one(ReturnSuccess::value(
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
Ok(ActionStream::one(ReturnSuccess::value(
UntaggedValue::string(get_full_help(&Command, &args.scope)).into_value(Tag::unknown()),
)))
}

View file

@ -30,7 +30,7 @@ impl WholeStreamCommand for Date {
"Format a given date using the given format string."
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
format(args)
}
@ -50,7 +50,7 @@ impl WholeStreamCommand for Date {
}
}
pub fn format(args: CommandArgs) -> Result<OutputStream, ShellError> {
pub fn format(args: CommandArgs) -> Result<ActionStream, ShellError> {
let tag = args.call_info.name_tag.clone();
let (FormatArgs { format, table }, input) = args.process()?;
@ -91,7 +91,7 @@ pub fn format(args: CommandArgs) -> Result<OutputStream, ShellError> {
&tag,
)),
})
.to_output_stream())
.to_action_stream())
}
#[cfg(test)]

View file

@ -20,7 +20,7 @@ impl WholeStreamCommand for Date {
"List supported time zones."
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
list_timezone(args)
}
@ -40,7 +40,7 @@ impl WholeStreamCommand for Date {
}
}
fn list_timezone(args: CommandArgs) -> Result<OutputStream, ShellError> {
fn list_timezone(args: CommandArgs) -> Result<ActionStream, ShellError> {
let args = args.evaluate_once()?;
let tag = args.call_info.name_tag.clone();
@ -57,7 +57,7 @@ fn list_timezone(args: CommandArgs) -> Result<OutputStream, ShellError> {
))
});
Ok(list.into_iter().to_output_stream())
Ok(list.into_iter().to_action_stream())
}
#[cfg(test)]

View file

@ -19,12 +19,12 @@ impl WholeStreamCommand for Date {
"Get the current date."
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
now(args)
}
}
pub fn now(args: CommandArgs) -> Result<OutputStream, ShellError> {
pub fn now(args: CommandArgs) -> Result<ActionStream, ShellError> {
let args = args.evaluate_once()?;
let tag = args.call_info.name_tag.clone();
@ -32,7 +32,7 @@ pub fn now(args: CommandArgs) -> Result<OutputStream, ShellError> {
let value = UntaggedValue::date(now.with_timezone(now.offset())).into_value(&tag);
Ok(OutputStream::one(value))
Ok(ActionStream::one(value))
}
#[cfg(test)]

View file

@ -20,7 +20,7 @@ impl WholeStreamCommand for Date {
"Print the date in a structured table."
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
to_table(args)
}
@ -33,7 +33,7 @@ impl WholeStreamCommand for Date {
}
}
fn to_table(args: CommandArgs) -> Result<OutputStream, ShellError> {
fn to_table(args: CommandArgs) -> Result<ActionStream, ShellError> {
let args = args.evaluate_once()?;
let tag = args.call_info.name_tag.clone();
let input = args.input;
@ -87,7 +87,7 @@ fn to_table(args: CommandArgs) -> Result<OutputStream, ShellError> {
&tag,
)),
})
.to_output_stream())
.to_action_stream())
}
#[cfg(test)]

View file

@ -33,7 +33,7 @@ impl WholeStreamCommand for Date {
"Use 'date list-timezone' to list all supported time zones."
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
to_timezone(args)
}
@ -58,7 +58,7 @@ impl WholeStreamCommand for Date {
}
}
fn to_timezone(args: CommandArgs) -> Result<OutputStream, ShellError> {
fn to_timezone(args: CommandArgs) -> Result<ActionStream, ShellError> {
let tag = args.call_info.name_tag.clone();
let (DateToTimeZoneArgs { timezone }, input) = args.process()?;
@ -85,7 +85,7 @@ fn to_timezone(args: CommandArgs) -> Result<OutputStream, ShellError> {
&tag,
)),
})
.to_output_stream())
.to_action_stream())
}
fn error_message(err: ParseErrorKind) -> &'static str {

View file

@ -21,7 +21,7 @@ impl WholeStreamCommand for Date {
"return the current date in utc."
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
utc(args)
}
}

View file

@ -23,12 +23,12 @@ impl WholeStreamCommand for Debug {
"Print the Rust debug representation of the values."
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
debug_value(args)
}
}
fn debug_value(args: CommandArgs) -> Result<OutputStream, ShellError> {
fn debug_value(args: CommandArgs) -> Result<ActionStream, ShellError> {
let (DebugArgs { raw }, input) = args.process()?;
Ok(input
.map(move |v| {
@ -40,7 +40,7 @@ fn debug_value(args: CommandArgs) -> Result<OutputStream, ShellError> {
ReturnSuccess::debug_value(v)
}
})
.to_output_stream())
.to_action_stream())
}
#[cfg(test)]

View file

@ -34,11 +34,11 @@ impl WholeStreamCommand for Def {
"Create a command and set it to a definition."
}
fn run(&self, _args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, _args: CommandArgs) -> Result<ActionStream, ShellError> {
// Currently, we don't do anything here because we should have already
// installed the definition as we entered the scope
// We just create a command so that we can get proper coloring
Ok(OutputStream::empty())
Ok(ActionStream::empty())
}
fn examples(&self) -> Vec<Example> {

View file

@ -32,7 +32,7 @@ impl WholeStreamCommand for Default {
"Sets a default row's column if missing."
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
default(args)
}
@ -45,7 +45,7 @@ impl WholeStreamCommand for Default {
}
}
fn default(args: CommandArgs) -> Result<OutputStream, ShellError> {
fn default(args: CommandArgs) -> Result<ActionStream, ShellError> {
let (DefaultArgs { column, value }, input) = args.process()?;
Ok(input
@ -67,7 +67,7 @@ fn default(args: CommandArgs) -> Result<OutputStream, ShellError> {
ReturnSuccess::value(item)
}
})
.to_output_stream())
.to_action_stream())
}
#[cfg(test)]

View file

@ -22,12 +22,12 @@ impl WholeStreamCommand for Describe {
"Describes the objects in the stream."
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
describe(args)
}
}
pub fn describe(args: CommandArgs) -> Result<OutputStream, ShellError> {
pub fn describe(args: CommandArgs) -> Result<ActionStream, ShellError> {
Ok(args
.input
.map(|row| {
@ -36,7 +36,7 @@ pub fn describe(args: CommandArgs) -> Result<OutputStream, ShellError> {
UntaggedValue::string(name).into_value(Tag::unknown_anchor(row.tag.span)),
)
})
.to_output_stream())
.to_action_stream())
}
#[cfg(test)]

View file

@ -31,7 +31,7 @@ impl WholeStreamCommand for Do {
"Runs a block, optionally ignoring errors."
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
do_(args)
}
@ -51,7 +51,7 @@ impl WholeStreamCommand for Do {
}
}
fn do_(raw_args: CommandArgs) -> Result<OutputStream, ShellError> {
fn do_(raw_args: CommandArgs) -> Result<ActionStream, ShellError> {
let external_redirection = raw_args.call_info.args.external_redirection;
let context = EvaluationContext::from_args(&raw_args);
@ -96,12 +96,12 @@ fn do_(raw_args: CommandArgs) -> Result<OutputStream, ShellError> {
Ok(mut stream) => {
let output = stream.drain_vec();
context.clear_errors();
Ok(output.into_iter().to_output_stream())
Ok(output.into_iter().to_action_stream())
}
Err(_) => Ok(OutputStream::empty()),
Err(_) => Ok(ActionStream::empty()),
}
} else {
result.map(|x| x.to_output_stream())
result.map(|x| x.to_action_stream())
}
}

View file

@ -29,7 +29,7 @@ impl WholeStreamCommand for SubCommand {
"Remove the last number of columns. If you want to remove columns by name, try 'reject'."
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
drop(args)
}
@ -47,7 +47,7 @@ impl WholeStreamCommand for SubCommand {
}
}
fn drop(args: CommandArgs) -> Result<OutputStream, ShellError> {
fn drop(args: CommandArgs) -> Result<ActionStream, ShellError> {
let (Arguments { columns }, input) = args.process()?;
let to_drop = if let Some(quantity) = columns {
@ -69,7 +69,7 @@ fn drop(args: CommandArgs) -> Result<OutputStream, ShellError> {
select_fields(&item, descs, item.tag())
})
.map(ReturnSuccess::value)
.to_output_stream())
.to_action_stream())
}
#[cfg(test)]

View file

@ -28,7 +28,7 @@ impl WholeStreamCommand for Command {
"Remove the last number of rows or columns."
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
drop(args)
}
@ -51,7 +51,7 @@ impl WholeStreamCommand for Command {
}
}
fn drop(args: CommandArgs) -> Result<OutputStream, ShellError> {
fn drop(args: CommandArgs) -> Result<ActionStream, ShellError> {
let (Arguments { rows }, input) = args.process()?;
let v: Vec<_> = input.into_vec();
@ -62,7 +62,7 @@ fn drop(args: CommandArgs) -> Result<OutputStream, ShellError> {
};
Ok(if rows_to_drop == 0 {
v.into_iter().to_output_stream()
v.into_iter().to_action_stream()
} else {
let k = if v.len() < rows_to_drop {
0
@ -72,6 +72,6 @@ fn drop(args: CommandArgs) -> Result<OutputStream, ShellError> {
let iter = v.into_iter().take(k);
iter.to_output_stream()
iter.to_action_stream()
})
}

View file

@ -70,7 +70,7 @@ impl WholeStreamCommand for Du {
"Find disk usage sizes of specified items."
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
du(args)
}
@ -83,7 +83,7 @@ impl WholeStreamCommand for Du {
}
}
fn du(args: CommandArgs) -> Result<OutputStream, ShellError> {
fn du(args: CommandArgs) -> Result<ActionStream, ShellError> {
let tag = args.call_info.name_tag.clone();
let ctrl_c = args.ctrl_c.clone();
let ctrl_c_copy = ctrl_c.clone();
@ -150,7 +150,7 @@ fn du(args: CommandArgs) -> Result<OutputStream, ShellError> {
Err(e) => vec![Err(e)],
})
.interruptible(ctrl_c_copy)
.to_output_stream())
.to_action_stream())
}
fn glob_err_into(e: GlobError) -> ShellError {

View file

@ -90,7 +90,7 @@ pub fn process_row(
context.scope.exit_scope();
Ok(result?.to_output_stream())
result
}
pub(crate) fn make_indexed_item(index: usize, item: Value) -> Value {
@ -121,7 +121,7 @@ fn each(raw_args: CommandArgs) -> Result<OutputStream, ShellError> {
match process_row(block, context, row) {
Ok(s) => s,
Err(e) => OutputStream::one(Err(e)),
Err(e) => OutputStream::one(Value::error(e)),
}
})
.flatten()
@ -135,7 +135,7 @@ fn each(raw_args: CommandArgs) -> Result<OutputStream, ShellError> {
match process_row(block, context, input) {
Ok(s) => s,
Err(e) => OutputStream::one(Err(e)),
Err(e) => OutputStream::one(Value::error(e)),
}
})
.flatten()

View file

@ -2,9 +2,7 @@ use crate::commands::each::process_row;
use crate::prelude::*;
use nu_engine::WholeStreamCommand;
use nu_errors::ShellError;
use nu_protocol::{
hir::CapturedBlock, ReturnSuccess, Signature, SyntaxShape, UntaggedValue, Value,
};
use nu_protocol::{hir::CapturedBlock, Signature, SyntaxShape, UntaggedValue, Value};
use nu_source::Tagged;
use serde::Deserialize;
@ -44,7 +42,7 @@ impl WholeStreamCommand for EachGroup {
}]
}
fn run(&self, raw_args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, raw_args: CommandArgs) -> Result<ActionStream, ShellError> {
let context = Arc::new(EvaluationContext::from_args(&raw_args));
let (each_args, input): (EachGroupArgs, _) = raw_args.process()?;
let block = Arc::new(Box::new(each_args.block));
@ -56,7 +54,7 @@ impl WholeStreamCommand for EachGroup {
input,
};
Ok(each_group_iterator.flatten().to_output_stream())
Ok(each_group_iterator.flatten().to_action_stream())
}
}
@ -122,20 +120,9 @@ pub(crate) fn run_block_on_vec(
// If it returned multiple values, we need to put them into a table and
// return that.
let result = vec.into_iter().collect::<Result<Vec<ReturnSuccess>, _>>();
let result_table = match result {
Ok(t) => t,
Err(e) => return OutputStream::one(Err(e)),
};
let table = result_table
.into_iter()
.filter_map(|x| x.raw_value())
.collect();
OutputStream::one(Ok(ReturnSuccess::Value(UntaggedValue::Table(table).into())))
OutputStream::one(UntaggedValue::Table(vec).into_untagged_value())
}
Err(e) => OutputStream::one(Err(e)),
Err(e) => OutputStream::one(Value::error(e)),
}
}

View file

@ -49,7 +49,7 @@ impl WholeStreamCommand for EachWindow {
}]
}
fn run(&self, raw_args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, raw_args: CommandArgs) -> Result<ActionStream, ShellError> {
let context = Arc::new(EvaluationContext::from_args(&raw_args));
let (each_args, mut input): (EachWindowArgs, _) = raw_args.process()?;
let block = Arc::new(Box::new(each_args.block));
@ -83,7 +83,7 @@ impl WholeStreamCommand for EachWindow {
})
.filter_map(|x| x)
.flatten()
.to_output_stream())
.to_action_stream())
}
}

View file

@ -3,9 +3,7 @@ use bigdecimal::Zero;
use nu_engine::WholeStreamCommand;
use nu_errors::ShellError;
use nu_protocol::hir::Operator;
use nu_protocol::{
Primitive, Range, RangeInclusion, ReturnSuccess, Signature, SyntaxShape, UntaggedValue, Value,
};
use nu_protocol::{Primitive, Range, RangeInclusion, Signature, SyntaxShape, UntaggedValue, Value};
pub struct Echo;
@ -22,7 +20,7 @@ impl WholeStreamCommand for Echo {
"Echo the arguments back to the user."
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run(&self, args: CommandArgs) -> Result<InputStream, ShellError> {
echo(args)
}
@ -42,31 +40,26 @@ impl WholeStreamCommand for Echo {
}
}
fn echo(args: CommandArgs) -> Result<OutputStream, ShellError> {
fn echo(args: CommandArgs) -> Result<InputStream, ShellError> {
let args = args.evaluate_once()?;
let rest: Vec<Value> = args.rest(0)?;
let stream = rest.into_iter().map(|i| match i.as_string() {
Ok(s) => OutputStream::one(Ok(ReturnSuccess::Value(
UntaggedValue::string(s).into_value(i.tag.clone()),
))),
Ok(s) => InputStream::one(UntaggedValue::string(s).into_value(i.tag.clone())),
_ => match i {
Value {
value: UntaggedValue::Table(table),
..
} => table
.into_iter()
.map(ReturnSuccess::value)
.to_output_stream(),
} => InputStream::from_stream(table.into_iter()),
Value {
value: UntaggedValue::Primitive(Primitive::Range(range)),
tag,
} => RangeIterator::new(*range, tag).to_output_stream(),
x => OutputStream::one(Ok(ReturnSuccess::Value(x))),
} => InputStream::from_stream(RangeIterator::new(*range, tag)),
x => InputStream::one(x),
},
});
Ok(stream.flatten().to_output_stream())
Ok(InputStream::from_stream(stream.flatten()))
}
struct RangeIterator {
@ -77,6 +70,7 @@ struct RangeIterator {
moves_up: bool,
one: UntaggedValue,
negative_one: UntaggedValue,
done: bool,
}
impl RangeIterator {
@ -99,14 +93,18 @@ impl RangeIterator {
is_end_inclusive: matches!(range.to.1, RangeInclusion::Inclusive),
one: UntaggedValue::int(1),
negative_one: UntaggedValue::int(-1),
done: false,
}
}
}
impl Iterator for RangeIterator {
type Item = Result<ReturnSuccess, ShellError>;
type Item = Value;
fn next(&mut self) -> Option<Self::Item> {
use std::cmp::Ordering;
if self.done {
return None;
}
let ordering = if self.end == UntaggedValue::Primitive(Primitive::Nothing) {
Ordering::Less
@ -129,11 +127,15 @@ impl Iterator for RangeIterator {
UntaggedValue::Primitive(Primitive::Decimal(y)),
) => (BigDecimal::zero() + x).cmp(y),
_ => {
return Some(Err(ShellError::labeled_error(
"Cannot create range",
"unsupported range",
self.tag.span,
)))
self.done = true;
return Some(
UntaggedValue::Error(ShellError::labeled_error(
"Cannot create range",
"unsupported range",
self.tag.span,
))
.into_untagged_value(),
);
}
}
};
@ -147,15 +149,19 @@ impl Iterator for RangeIterator {
Ok(result) => result,
Err((left_type, right_type)) => {
return Some(Err(ShellError::coerce_error(
left_type.spanned(self.tag.span),
right_type.spanned(self.tag.span),
)));
self.done = true;
return Some(
UntaggedValue::Error(ShellError::coerce_error(
left_type.spanned(self.tag.span),
right_type.spanned(self.tag.span),
))
.into_untagged_value(),
);
}
};
std::mem::swap(&mut self.curr, &mut next);
Some(ReturnSuccess::value(next.into_value(self.tag.clone())))
Some(next.into_value(self.tag.clone()))
} else if !self.moves_up
&& (ordering == Ordering::Greater
|| self.is_end_inclusive && ordering == Ordering::Equal)
@ -166,15 +172,19 @@ impl Iterator for RangeIterator {
let mut next = match next_value {
Ok(result) => result,
Err((left_type, right_type)) => {
return Some(Err(ShellError::coerce_error(
left_type.spanned(self.tag.span),
right_type.spanned(self.tag.span),
)));
self.done = true;
return Some(
UntaggedValue::Error(ShellError::coerce_error(
left_type.spanned(self.tag.span),
right_type.spanned(self.tag.span),
))
.into_untagged_value(),
);
}
};
std::mem::swap(&mut self.curr, &mut next);
Some(ReturnSuccess::value(next.into_value(self.tag.clone())))
Some(next.into_value(self.tag.clone()))
} else {
None
}

View file

@ -33,7 +33,7 @@ impl WholeStreamCommand for Command {
"Check for empty values."
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
is_empty(args)
}
@ -79,7 +79,7 @@ impl WholeStreamCommand for Command {
}
}
fn is_empty(args: CommandArgs) -> Result<OutputStream, ShellError> {
fn is_empty(args: CommandArgs) -> Result<ActionStream, ShellError> {
let tag = args.call_info.name_tag.clone();
let name_tag = Arc::new(args.call_info.name_tag.clone());
let context = Arc::new(EvaluationContext::from_args(&args));
@ -100,11 +100,11 @@ fn is_empty(args: CommandArgs) -> Result<OutputStream, ShellError> {
match process_row(context, input, block, columns, tag) {
Ok(s) => s,
Err(e) => OutputStream::one(Err(e)),
Err(e) => ActionStream::one(Err(e)),
}
})
.flatten()
.to_output_stream());
.to_action_stream());
}
Ok(input
@ -116,11 +116,11 @@ fn is_empty(args: CommandArgs) -> Result<OutputStream, ShellError> {
match process_row(context, input, block, columns, tag) {
Ok(s) => s,
Err(e) => OutputStream::one(Err(e)),
Err(e) => ActionStream::one(Err(e)),
}
})
.flatten()
.to_output_stream())
.to_action_stream())
}
fn process_row(
@ -129,7 +129,7 @@ fn process_row(
default_block: Arc<Option<Box<CapturedBlock>>>,
column_paths: Vec<ColumnPath>,
tag: Arc<Tag>,
) -> Result<OutputStream, ShellError> {
) -> Result<ActionStream, ShellError> {
let _tag = &*tag;
let mut out = Arc::new(None);
let results = Arc::make_mut(&mut out);
@ -178,7 +178,7 @@ fn process_row(
ref tag,
} => {
if column_paths.is_empty() {
Ok(OutputStream::one(ReturnSuccess::value({
Ok(ActionStream::one(ReturnSuccess::value({
let is_empty = input.is_empty();
if default_block.is_some() {
@ -221,10 +221,10 @@ fn process_row(
}
}
Ok(OutputStream::one(ReturnSuccess::value(obj)))
Ok(ActionStream::one(ReturnSuccess::value(obj)))
}
}
other => Ok(OutputStream::one(ReturnSuccess::value({
other => Ok(ActionStream::one(ReturnSuccess::value({
if other.is_empty() {
results
.clone()

View file

@ -50,7 +50,7 @@ For a more complete list of encodings please refer to the encoding_rs
documentation link at https://docs.rs/encoding_rs/0.8.28/encoding_rs/#statics"#
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
enter(args)
}
@ -75,7 +75,7 @@ documentation link at https://docs.rs/encoding_rs/0.8.28/encoding_rs/#statics"#
}
}
fn enter(raw_args: CommandArgs) -> Result<OutputStream, ShellError> {
fn enter(raw_args: CommandArgs) -> Result<ActionStream, ShellError> {
let scope = raw_args.scope.clone();
let shell_manager = raw_args.shell_manager.clone();
let head = raw_args.call_info.args.head.clone();
@ -88,7 +88,7 @@ fn enter(raw_args: CommandArgs) -> Result<OutputStream, ShellError> {
let location_string = location.display().to_string();
if location.is_dir() {
Ok(OutputStream::one(ReturnSuccess::action(
Ok(ActionStream::one(ReturnSuccess::action(
CommandAction::EnterShell(location_string),
)))
} else {
@ -129,8 +129,8 @@ fn enter(raw_args: CommandArgs) -> Result<OutputStream, ShellError> {
scope,
};
let tag = tagged_contents.tag.clone();
let mut result =
converter.run(new_args.with_input(vec![tagged_contents]))?;
let mut result = converter
.run_with_actions(new_args.with_input(vec![tagged_contents]))?;
let result_vec: Vec<Result<ReturnSuccess, ShellError>> = result.drain_vec();
Ok(result_vec
.into_iter()
@ -143,19 +143,19 @@ fn enter(raw_args: CommandArgs) -> Result<OutputStream, ShellError> {
),
x => x,
})
.to_output_stream())
.to_action_stream())
} else {
Ok(OutputStream::one(ReturnSuccess::action(
Ok(ActionStream::one(ReturnSuccess::action(
CommandAction::EnterValueShell(tagged_contents),
)))
}
} else {
Ok(OutputStream::one(ReturnSuccess::action(
Ok(ActionStream::one(ReturnSuccess::action(
CommandAction::EnterValueShell(tagged_contents),
)))
}
}
_ => Ok(OutputStream::one(ReturnSuccess::action(
_ => Ok(ActionStream::one(ReturnSuccess::action(
CommandAction::EnterValueShell(tagged_contents),
))),
}

View file

@ -35,7 +35,7 @@ impl WholeStreamCommand for Every {
"Show (or skip) every n-th row, starting from the first one."
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
every(args)
}
@ -62,7 +62,7 @@ impl WholeStreamCommand for Every {
}
}
fn every(args: CommandArgs) -> Result<OutputStream, ShellError> {
fn every(args: CommandArgs) -> Result<ActionStream, ShellError> {
let (EveryArgs { stride, skip }, input) = args.process()?;
let stride = stride.item;
@ -80,7 +80,7 @@ fn every(args: CommandArgs) -> Result<OutputStream, ShellError> {
None
}
})
.to_output_stream())
.to_action_stream())
}
#[cfg(test)]

View file

@ -31,7 +31,7 @@ impl WholeStreamCommand for Exec {
"Execute command."
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
exec(args)
}
@ -52,7 +52,7 @@ impl WholeStreamCommand for Exec {
}
#[cfg(unix)]
fn exec(args: CommandArgs) -> Result<OutputStream, ShellError> {
fn exec(args: CommandArgs) -> Result<ActionStream, ShellError> {
use std::os::unix::process::CommandExt;
use std::process::Command;
@ -74,7 +74,7 @@ fn exec(args: CommandArgs) -> Result<OutputStream, ShellError> {
}
#[cfg(not(unix))]
fn exec(args: CommandArgs) -> Result<OutputStream, ShellError> {
fn exec(args: CommandArgs) -> Result<ActionStream, ShellError> {
Err(ShellError::labeled_error(
"Error on exec",
"exec is not supported on your platform",

View file

@ -23,7 +23,7 @@ impl WholeStreamCommand for Exit {
"Exit the current shell (or all shells)."
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
exit(args)
}
@ -43,7 +43,7 @@ impl WholeStreamCommand for Exit {
}
}
pub fn exit(args: CommandArgs) -> Result<OutputStream, ShellError> {
pub fn exit(args: CommandArgs) -> Result<ActionStream, ShellError> {
let args = args.evaluate_once()?;
let code = if let Some(value) = args.call_info.args.nth(0) {
@ -58,7 +58,7 @@ pub fn exit(args: CommandArgs) -> Result<OutputStream, ShellError> {
CommandAction::LeaveShell(code)
};
Ok(OutputStream::one(ReturnSuccess::action(command_action)))
Ok(ActionStream::one(ReturnSuccess::action(command_action)))
}
#[cfg(test)]

View file

@ -28,7 +28,7 @@ impl WholeStreamCommand for First {
"Show only the first number of rows."
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
first(args)
}
@ -51,7 +51,7 @@ impl WholeStreamCommand for First {
}
}
fn first(args: CommandArgs) -> Result<OutputStream, ShellError> {
fn first(args: CommandArgs) -> Result<ActionStream, ShellError> {
let (FirstArgs { rows }, input) = args.process()?;
let rows_desired = if let Some(quantity) = rows {
*quantity
@ -59,7 +59,7 @@ fn first(args: CommandArgs) -> Result<OutputStream, ShellError> {
1
};
Ok(input.take(rows_desired).to_output_stream())
Ok(input.take(rows_desired).to_action_stream())
}
#[cfg(test)]

View file

@ -26,7 +26,7 @@ impl WholeStreamCommand for Command {
"Flatten the table."
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
flatten(args)
}
@ -51,14 +51,14 @@ impl WholeStreamCommand for Command {
}
}
fn flatten(args: CommandArgs) -> Result<OutputStream, ShellError> {
fn flatten(args: CommandArgs) -> Result<ActionStream, ShellError> {
let tag = args.call_info.name_tag.clone();
let (Arguments { rest: columns }, input) = args.process()?;
Ok(input
.map(move |item| flat_value(&columns, &item, &tag).into_iter())
.flatten()
.to_output_stream())
.to_action_stream())
}
enum TableInside<'a> {

View file

@ -30,7 +30,7 @@ impl WholeStreamCommand for Format {
"Format columns into a string using a simple pattern."
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
format_command(args)
}
@ -43,7 +43,7 @@ impl WholeStreamCommand for Format {
}
}
fn format_command(args: CommandArgs) -> Result<OutputStream, ShellError> {
fn format_command(args: CommandArgs) -> Result<ActionStream, ShellError> {
let ctx = Arc::new(EvaluationContext::from_args(&args));
let (FormatArgs { pattern }, input) = args.process()?;
@ -84,7 +84,7 @@ fn format_command(args: CommandArgs) -> Result<OutputStream, ShellError> {
ReturnSuccess::value(UntaggedValue::string(output).into_untagged_value())
})
.to_output_stream())
.to_action_stream())
}
#[derive(Debug)]

View file

@ -39,7 +39,7 @@ impl WholeStreamCommand for FileSize {
"Converts a column of filesizes to some specified format"
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
filesize(args)
}
@ -63,7 +63,7 @@ fn process_row(
input: Value,
format: Tagged<String>,
field: Arc<ColumnPath>,
) -> Result<OutputStream, ShellError> {
) -> Result<ActionStream, ShellError> {
Ok({
let replace_for = get_data_by_column_path(&input, &field, move |_, _, error| error);
match replace_for {
@ -75,7 +75,7 @@ fn process_row(
{
let byte_format = InlineShape::format_bytes(&fs, Some(&format.item));
let byte_value = Value::from(byte_format.1);
OutputStream::one(ReturnSuccess::value(
ActionStream::one(ReturnSuccess::value(
input.replace_data_at_column_path(&field, byte_value).expect("Given that the existence check was already done, this shouldn't trigger never"),
))
} else {
@ -86,12 +86,12 @@ fn process_row(
));
}
}
Err(e) => OutputStream::one(Err(e)),
Err(e) => ActionStream::one(Err(e)),
}
})
}
fn filesize(raw_args: CommandArgs) -> Result<OutputStream, ShellError> {
fn filesize(raw_args: CommandArgs) -> Result<ActionStream, ShellError> {
let (Arguments { field, format }, input) = raw_args.process()?;
let field = Arc::new(field);
@ -102,11 +102,11 @@ fn filesize(raw_args: CommandArgs) -> Result<OutputStream, ShellError> {
match process_row(input, format, field) {
Ok(s) => s,
Err(e) => OutputStream::one(Err(e)),
Err(e) => ActionStream::one(Err(e)),
}
})
.flatten()
.to_output_stream())
.to_action_stream())
}
#[cfg(test)]

View file

@ -18,8 +18,8 @@ impl WholeStreamCommand for From {
"Parse content (string or binary) as a table (input format based on subcommand, like csv, ini, json, toml)."
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
Ok(OutputStream::one(ReturnSuccess::value(
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
Ok(ActionStream::one(ReturnSuccess::value(
UntaggedValue::string(get_full_help(&From, &args.scope)).into_value(Tag::unknown()),
)))
}

View file

@ -36,7 +36,7 @@ impl WholeStreamCommand for FromCsv {
"Parse text as .csv and create table."
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
from_csv(args)
}
@ -66,7 +66,7 @@ impl WholeStreamCommand for FromCsv {
}
}
fn from_csv(args: CommandArgs) -> Result<OutputStream, ShellError> {
fn from_csv(args: CommandArgs) -> Result<ActionStream, ShellError> {
let name = args.call_info.name_tag.clone();
let (

View file

@ -51,7 +51,7 @@ pub fn from_delimited_data(
format_name: &'static str,
input: InputStream,
name: Tag,
) -> Result<OutputStream, ShellError> {
) -> Result<ActionStream, ShellError> {
let name_tag = name;
let concat_string = input.collect_string(name_tag.clone())?;
let sample_lines = concat_string.item.lines().take(3).collect_vec().join("\n");
@ -61,8 +61,8 @@ pub fn from_delimited_data(
Value {
value: UntaggedValue::Table(list),
..
} => Ok(list.into_iter().to_output_stream()),
x => Ok(OutputStream::one(x)),
} => Ok(list.into_iter().to_action_stream()),
x => Ok(ActionStream::one(x)),
},
Err(err) => {
let line_one = match pretty_csv_error(err) {

View file

@ -34,7 +34,7 @@ impl WholeStreamCommand for FromEml {
"Parse text as .eml and create table."
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
from_eml(args)
}
}
@ -72,7 +72,7 @@ fn headerfieldvalue_to_value(tag: &Tag, value: &HeaderFieldValue) -> UntaggedVal
}
}
fn from_eml(args: CommandArgs) -> Result<OutputStream, ShellError> {
fn from_eml(args: CommandArgs) -> Result<ActionStream, ShellError> {
let tag = args.call_info.name_tag.clone();
let (eml_args, input): (FromEmlArgs, _) = args.process()?;
let value = input.collect_string(tag.clone())?;
@ -115,7 +115,7 @@ fn from_eml(args: CommandArgs) -> Result<OutputStream, ShellError> {
dict.insert_untagged("Body", UntaggedValue::string(body));
}
Ok(OutputStream::one(ReturnSuccess::value(dict.into_value())))
Ok(ActionStream::one(ReturnSuccess::value(dict.into_value())))
}
#[cfg(test)]

View file

@ -22,12 +22,12 @@ impl WholeStreamCommand for FromIcs {
"Parse text as .ics and create table."
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
from_ics(args)
}
}
fn from_ics(args: CommandArgs) -> Result<OutputStream, ShellError> {
fn from_ics(args: CommandArgs) -> Result<ActionStream, ShellError> {
let args = args.evaluate_once()?;
let tag = args.name_tag();
let input = args.input;
@ -52,7 +52,7 @@ fn from_ics(args: CommandArgs) -> Result<OutputStream, ShellError> {
}
}
Ok(output.into_iter().to_output_stream())
Ok(output.into_iter().to_action_stream())
}
fn calendar_to_value(calendar: IcalCalendar, tag: Tag) -> Value {

View file

@ -19,7 +19,7 @@ impl WholeStreamCommand for FromIni {
"Parse text as .ini and create table"
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
from_ini(args)
}
}
@ -59,7 +59,7 @@ pub fn from_ini_string_to_value(
Ok(convert_ini_top_to_nu_value(&v, tag))
}
fn from_ini(args: CommandArgs) -> Result<OutputStream, ShellError> {
fn from_ini(args: CommandArgs) -> Result<ActionStream, ShellError> {
let args = args.evaluate_once()?;
let tag = args.name_tag();
let input = args.input;
@ -70,8 +70,8 @@ fn from_ini(args: CommandArgs) -> Result<OutputStream, ShellError> {
Value {
value: UntaggedValue::Table(list),
..
} => Ok(list.into_iter().to_output_stream()),
x => Ok(OutputStream::one(x)),
} => Ok(list.into_iter().to_action_stream()),
x => Ok(ActionStream::one(x)),
},
Err(_) => Err(ShellError::labeled_error_with_secondary(
"Could not parse as INI",

View file

@ -27,7 +27,7 @@ impl WholeStreamCommand for FromJson {
"Parse text as .json and create table."
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
from_json(args)
}
}
@ -67,7 +67,7 @@ pub fn from_json_string_to_value(s: String, tag: impl Into<Tag>) -> nu_json::Res
Ok(convert_json_value_to_nu_value(&v, tag))
}
fn from_json(args: CommandArgs) -> Result<OutputStream, ShellError> {
fn from_json(args: CommandArgs) -> Result<ActionStream, ShellError> {
let name_tag = args.call_info.name_tag.clone();
let (FromJsonArgs { objects }, input) = args.process()?;
@ -100,7 +100,7 @@ fn from_json(args: CommandArgs) -> Result<OutputStream, ShellError> {
}
}
})
.to_output_stream())
.to_action_stream())
} else {
match from_json_string_to_value(concat_string.item, name_tag.clone()) {
Ok(x) => match x {
@ -110,16 +110,16 @@ fn from_json(args: CommandArgs) -> Result<OutputStream, ShellError> {
} => Ok(list
.into_iter()
.map(ReturnSuccess::value)
.to_output_stream()),
.to_action_stream()),
x => Ok(OutputStream::one(ReturnSuccess::value(x))),
x => Ok(ActionStream::one(ReturnSuccess::value(x))),
},
Err(e) => {
let mut message = "Could not parse as JSON (".to_string();
message.push_str(&e.to_string());
message.push(')');
Ok(OutputStream::one(Err(
Ok(ActionStream::one(Err(
ShellError::labeled_error_with_secondary(
message,
"input cannot be parsed as JSON",

View file

@ -30,12 +30,12 @@ impl WholeStreamCommand for FromOds {
"Parse OpenDocument Spreadsheet(.ods) data and create table."
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
from_ods(args)
}
}
fn from_ods(args: CommandArgs) -> Result<OutputStream, ShellError> {
fn from_ods(args: CommandArgs) -> Result<ActionStream, ShellError> {
let tag = args.call_info.name_tag.clone();
let span = tag.span;
@ -87,7 +87,7 @@ fn from_ods(args: CommandArgs) -> Result<OutputStream, ShellError> {
}
}
Ok(OutputStream::one(ReturnSuccess::value(dict.into_value())))
Ok(ActionStream::one(ReturnSuccess::value(dict.into_value())))
}
#[cfg(test)]

View file

@ -45,7 +45,7 @@ impl WholeStreamCommand for FromSsv {
"Parse text as space-separated values and create a table. The default minimum number of spaces counted as a separator is 2."
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
from_ssv(args)
}
}
@ -246,7 +246,7 @@ fn from_ssv_string_to_value(
UntaggedValue::Table(rows).into_value(&tag)
}
fn from_ssv(args: CommandArgs) -> Result<OutputStream, ShellError> {
fn from_ssv(args: CommandArgs) -> Result<ActionStream, ShellError> {
let name = args.call_info.name_tag.clone();
let (
FromSsvArgs {
@ -276,8 +276,8 @@ fn from_ssv(args: CommandArgs) -> Result<OutputStream, ShellError> {
} => list
.into_iter()
.map(ReturnSuccess::value)
.to_output_stream(),
x => OutputStream::one(ReturnSuccess::value(x)),
.to_action_stream(),
x => ActionStream::one(ReturnSuccess::value(x)),
},
)
}

View file

@ -18,7 +18,7 @@ impl WholeStreamCommand for FromToml {
"Parse text as .toml and create table."
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
from_toml(args)
}
}
@ -60,7 +60,7 @@ pub fn from_toml_string_to_value(s: String, tag: impl Into<Tag>) -> Result<Value
Ok(convert_toml_value_to_nu_value(&v, tag))
}
pub fn from_toml(args: CommandArgs) -> Result<OutputStream, ShellError> {
pub fn from_toml(args: CommandArgs) -> Result<ActionStream, ShellError> {
let args = args.evaluate_once()?;
let tag = args.name_tag();
let input = args.input;
@ -75,8 +75,8 @@ pub fn from_toml(args: CommandArgs) -> Result<OutputStream, ShellError> {
} => list
.into_iter()
.map(ReturnSuccess::value)
.to_output_stream(),
x => OutputStream::one(ReturnSuccess::value(x)),
.to_action_stream(),
x => ActionStream::one(ReturnSuccess::value(x)),
},
Err(_) => {
return Err(ShellError::labeled_error_with_secondary(

View file

@ -28,12 +28,12 @@ impl WholeStreamCommand for FromTsv {
"Parse text as .tsv and create table."
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
from_tsv(args)
}
}
fn from_tsv(args: CommandArgs) -> Result<OutputStream, ShellError> {
fn from_tsv(args: CommandArgs) -> Result<ActionStream, ShellError> {
let name = args.call_info.name_tag.clone();
let (FromTsvArgs { noheaders }, input) = args.process()?;

View file

@ -18,12 +18,12 @@ impl WholeStreamCommand for FromUrl {
"Parse url-encoded string as a table."
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
from_url(args)
}
}
fn from_url(args: CommandArgs) -> Result<OutputStream, ShellError> {
fn from_url(args: CommandArgs) -> Result<ActionStream, ShellError> {
let args = args.evaluate_once()?;
let tag = args.name_tag();
let input = args.input;
@ -40,7 +40,7 @@ fn from_url(args: CommandArgs) -> Result<OutputStream, ShellError> {
row.insert_untagged(k, UntaggedValue::string(v));
}
Ok(OutputStream::one(ReturnSuccess::value(row.into_value())))
Ok(ActionStream::one(ReturnSuccess::value(row.into_value())))
}
_ => Err(ShellError::labeled_error_with_secondary(
"String not compatible with url-encoding",

View file

@ -21,12 +21,12 @@ impl WholeStreamCommand for FromVcf {
"Parse text as .vcf and create table."
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
from_vcf(args)
}
}
fn from_vcf(args: CommandArgs) -> Result<OutputStream, ShellError> {
fn from_vcf(args: CommandArgs) -> Result<ActionStream, ShellError> {
let args = args.evaluate_once()?;
let tag = args.name_tag();
let input = args.input;
@ -47,7 +47,7 @@ fn from_vcf(args: CommandArgs) -> Result<OutputStream, ShellError> {
let collected: Vec<_> = iter.collect();
Ok(collected.into_iter().to_output_stream())
Ok(collected.into_iter().to_action_stream())
}
fn contact_to_value(contact: VcardContact, tag: Tag) -> Value {

View file

@ -30,12 +30,12 @@ impl WholeStreamCommand for FromXlsx {
"Parse binary Excel(.xlsx) data and create table."
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
from_xlsx(args)
}
}
fn from_xlsx(args: CommandArgs) -> Result<OutputStream, ShellError> {
fn from_xlsx(args: CommandArgs) -> Result<ActionStream, ShellError> {
let tag = args.call_info.name_tag.clone();
let span = tag.span;
let (
@ -87,7 +87,7 @@ fn from_xlsx(args: CommandArgs) -> Result<OutputStream, ShellError> {
}
}
Ok(OutputStream::one(ReturnSuccess::value(dict.into_value())))
Ok(ActionStream::one(ReturnSuccess::value(dict.into_value())))
}
#[cfg(test)]

View file

@ -18,7 +18,7 @@ impl WholeStreamCommand for FromXml {
"Parse text as .xml and create table."
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
from_xml(args)
}
}
@ -94,7 +94,7 @@ pub fn from_xml_string_to_value(s: String, tag: impl Into<Tag>) -> Result<Value,
Ok(from_document_to_value(&parsed, tag))
}
fn from_xml(args: CommandArgs) -> Result<OutputStream, ShellError> {
fn from_xml(args: CommandArgs) -> Result<ActionStream, ShellError> {
let args = args.evaluate_once()?;
let tag = args.name_tag();
let input = args.input;
@ -110,8 +110,8 @@ fn from_xml(args: CommandArgs) -> Result<OutputStream, ShellError> {
} => list
.into_iter()
.map(ReturnSuccess::value)
.to_output_stream(),
x => OutputStream::one(ReturnSuccess::value(x)),
.to_action_stream(),
x => ActionStream::one(ReturnSuccess::value(x)),
},
Err(_) => {
return Err(ShellError::labeled_error_with_secondary(

View file

@ -18,7 +18,7 @@ impl WholeStreamCommand for FromYaml {
"Parse text as .yaml/.yml and create table."
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
from_yaml(args)
}
}
@ -38,7 +38,7 @@ impl WholeStreamCommand for FromYml {
"Parse text as .yaml/.yml and create table."
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
from_yaml(args)
}
}
@ -131,7 +131,7 @@ pub fn from_yaml_string_to_value(s: String, tag: impl Into<Tag>) -> Result<Value
convert_yaml_value_to_nu_value(&v, tag)
}
fn from_yaml(args: CommandArgs) -> Result<OutputStream, ShellError> {
fn from_yaml(args: CommandArgs) -> Result<ActionStream, ShellError> {
let args = args.evaluate_once()?;
let tag = args.name_tag();
let input = args.input;
@ -143,8 +143,8 @@ fn from_yaml(args: CommandArgs) -> Result<OutputStream, ShellError> {
Value {
value: UntaggedValue::Table(list),
..
} => Ok(list.into_iter().to_output_stream()),
x => Ok(OutputStream::one(x)),
} => Ok(list.into_iter().to_action_stream()),
x => Ok(ActionStream::one(x)),
},
Err(_) => Err(ShellError::labeled_error_with_secondary(
"Could not parse as YAML",

View file

@ -34,7 +34,7 @@ impl WholeStreamCommand for Command {
"Open given cells as text."
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
get(args)
}
@ -54,7 +54,7 @@ impl WholeStreamCommand for Command {
}
}
pub fn get(args: CommandArgs) -> Result<OutputStream, ShellError> {
pub fn get(args: CommandArgs) -> Result<ActionStream, ShellError> {
let (Arguments { mut rest }, mut input) = args.process()?;
let (column_paths, _) = arguments(&mut rest)?;
@ -66,7 +66,7 @@ pub fn get(args: CommandArgs) -> Result<OutputStream, ShellError> {
Ok(descs
.into_iter()
.map(ReturnSuccess::value)
.to_output_stream())
.to_action_stream())
} else {
trace!("get {:?}", column_paths);
let output_stream = input
@ -78,7 +78,7 @@ pub fn get(args: CommandArgs) -> Result<OutputStream, ShellError> {
.collect::<Vec<_>>()
})
.flatten()
.to_output_stream();
.to_action_stream();
Ok(output_stream)
}
}

View file

@ -2,7 +2,7 @@ use crate::prelude::*;
use crate::utils::suggestions::suggestions;
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;
use nu_value_ext::as_string;
@ -150,7 +150,7 @@ pub fn group_by(args: CommandArgs) -> Result<OutputStream, ShellError> {
match crate::commands::each::process_row(run, context, value.clone()) {
Ok(mut s) => {
let collection: Vec<Result<ReturnSuccess, ShellError>> = s.drain_vec();
let collection: Vec<Value> = s.drain_vec();
if collection.len() > 1 {
return Err(ShellError::labeled_error(
@ -161,14 +161,12 @@ pub fn group_by(args: CommandArgs) -> Result<OutputStream, ShellError> {
}
let value = match collection.get(0) {
Some(Ok(return_value)) => {
return_value.raw_value().unwrap_or_else(|| {
UntaggedValue::string(error_key).into_value(&name)
})
}
Some(Err(_)) | None => {
UntaggedValue::string(error_key).into_value(&name)
}
Some(Value {
value: UntaggedValue::Error(_),
..
})
| None => UntaggedValue::string(error_key).into_value(&name),
Some(return_value) => return_value.clone(),
};
keys.push(as_string(&value));
@ -220,7 +218,7 @@ pub fn group_by(args: CommandArgs) -> Result<OutputStream, ShellError> {
Grouper::ByColumn(column_name) => group(&column_name, &values, &name),
};
Ok(OutputStream::one(ReturnSuccess::value(group_value?)))
Ok(OutputStream::one(group_value?))
}
pub fn group(

View file

@ -37,7 +37,7 @@ impl WholeStreamCommand for GroupByDate {
"creates a table grouped by date."
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
group_by_date(args)
}
@ -58,7 +58,7 @@ enum GroupByColumn {
Name(Option<Tagged<String>>),
}
pub fn group_by_date(args: CommandArgs) -> Result<OutputStream, ShellError> {
pub fn group_by_date(args: CommandArgs) -> Result<ActionStream, ShellError> {
let name = args.call_info.name_tag.clone();
let (
GroupByDateArgs {
@ -125,7 +125,7 @@ pub fn group_by_date(args: CommandArgs) -> Result<OutputStream, ShellError> {
}
};
Ok(OutputStream::one(ReturnSuccess::value(value_result?)))
Ok(ActionStream::one(ReturnSuccess::value(value_result?)))
}
}

View file

@ -64,7 +64,7 @@ impl WholeStreamCommand for SubCommand {
"base64 encode or decode a value"
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
operate(args)
}
@ -95,7 +95,7 @@ impl WholeStreamCommand for SubCommand {
}
}
fn operate(args: CommandArgs) -> Result<OutputStream, ShellError> {
fn operate(args: CommandArgs) -> Result<ActionStream, ShellError> {
let name_tag = args.call_info.name_tag.clone();
let (
@ -109,7 +109,7 @@ fn operate(args: CommandArgs) -> Result<OutputStream, ShellError> {
) = args.process()?;
if encode.item && decode.item {
return Ok(OutputStream::one(Err(ShellError::labeled_error(
return Ok(ActionStream::one(Err(ShellError::labeled_error(
"only one of --decode and --encode flags can be used",
"conflicting flags",
name_tag,
@ -154,7 +154,7 @@ fn operate(args: CommandArgs) -> Result<OutputStream, ShellError> {
ReturnSuccess::value(ret)
}
})
.to_output_stream())
.to_action_stream())
}
fn action(

View file

@ -21,8 +21,8 @@ impl WholeStreamCommand for Command {
"Apply hash function."
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
Ok(OutputStream::one(ReturnSuccess::value(
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
Ok(ActionStream::one(ReturnSuccess::value(
UntaggedValue::string(get_full_help(&Command, &args.scope)).into_value(Tag::unknown()),
)))
}

View file

@ -30,7 +30,7 @@ impl WholeStreamCommand for SubCommand {
"md5 encode a value"
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
operate(args)
}
@ -56,7 +56,7 @@ impl WholeStreamCommand for SubCommand {
}
}
fn operate(args: CommandArgs) -> Result<OutputStream, ShellError> {
fn operate(args: CommandArgs) -> Result<ActionStream, ShellError> {
let (Arguments { rest }, input) = args.process()?;
let column_paths: Vec<_> = rest;
@ -78,7 +78,7 @@ fn operate(args: CommandArgs) -> Result<OutputStream, ShellError> {
ReturnSuccess::value(ret)
}
})
.to_output_stream())
.to_action_stream())
}
fn action(input: &Value, tag: impl Into<Tag>) -> Result<Value, ShellError> {

View file

@ -21,7 +21,7 @@ impl WholeStreamCommand for Headers {
"Use the first row of the table as column names."
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
headers(args)
}
@ -41,7 +41,7 @@ impl WholeStreamCommand for Headers {
}
}
pub fn headers(args: CommandArgs) -> Result<OutputStream, ShellError> {
pub fn headers(args: CommandArgs) -> Result<ActionStream, ShellError> {
let input = args.input;
let rows: Vec<Value> = input.collect();
@ -102,7 +102,7 @@ pub fn headers(args: CommandArgs) -> Result<OutputStream, ShellError> {
)),
}
})
.to_output_stream())
.to_action_stream())
}
#[cfg(test)]

View file

@ -31,12 +31,12 @@ impl WholeStreamCommand for Help {
"Display help information about commands."
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
help(args)
}
}
fn help(args: CommandArgs) -> Result<OutputStream, ShellError> {
fn help(args: CommandArgs) -> Result<ActionStream, ShellError> {
let name = args.call_info.name_tag.clone();
let scope = args.scope.clone();
let (HelpArgs { rest }, ..) = args.process()?;
@ -154,24 +154,24 @@ fn help(args: CommandArgs) -> Result<OutputStream, ShellError> {
ReturnSuccess::value(short_desc.into_value())
});
Ok(iterator.to_output_stream())
Ok(iterator.to_action_stream())
} else if rest[0].item == "generate_docs" {
Ok(OutputStream::one(ReturnSuccess::value(generate_docs(
Ok(ActionStream::one(ReturnSuccess::value(generate_docs(
&scope,
))))
} else if rest.len() == 2 {
// Check for a subcommand
let command_name = format!("{} {}", rest[0].item, rest[1].item);
if let Some(command) = scope.get_command(&command_name) {
Ok(OutputStream::one(ReturnSuccess::value(
Ok(ActionStream::one(ReturnSuccess::value(
UntaggedValue::string(get_full_help(command.stream_command(), &scope))
.into_value(Tag::unknown()),
)))
} else {
Ok(OutputStream::empty())
Ok(ActionStream::empty())
}
} else if let Some(command) = scope.get_command(&rest[0].item) {
Ok(OutputStream::one(ReturnSuccess::value(
Ok(ActionStream::one(ReturnSuccess::value(
UntaggedValue::string(get_full_help(command.stream_command(), &scope))
.into_value(Tag::unknown()),
)))
@ -205,7 +205,7 @@ Get the processes on your system actively using CPU:
You can also learn more at https://www.nushell.sh/book/"#;
Ok(OutputStream::one(ReturnSuccess::value(
Ok(ActionStream::one(ReturnSuccess::value(
UntaggedValue::string(msg).into_value(Tag::unknown()),
)))
}

View file

@ -31,7 +31,7 @@ impl WholeStreamCommand for Histogram {
"Creates a new table with a histogram based on the column name passed in."
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
histogram(args)
}
@ -57,7 +57,7 @@ impl WholeStreamCommand for Histogram {
}
}
pub fn histogram(args: CommandArgs) -> Result<OutputStream, ShellError> {
pub fn histogram(args: CommandArgs) -> Result<ActionStream, ShellError> {
let name = args.call_info.name_tag.clone();
let (input, args) = args.evaluate_once()?.parts();
@ -177,7 +177,7 @@ pub fn histogram(args: CommandArgs) -> Result<OutputStream, ShellError> {
ReturnSuccess::value(fact.into_value())
})
.to_output_stream())
.to_action_stream())
}
fn evaluator(by: ColumnPath) -> Box<dyn Fn(usize, &Value) -> Result<Value, ShellError> + Send> {

View file

@ -25,12 +25,12 @@ impl WholeStreamCommand for History {
"Display command history."
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
history(args)
}
}
fn history(args: CommandArgs) -> Result<OutputStream, ShellError> {
fn history(args: CommandArgs) -> Result<ActionStream, ShellError> {
let tag = args.call_info.name_tag.clone();
let ctx = EvaluationContext::from_args(&args);
let (Arguments { clear }, _) = args.process()?;
@ -44,7 +44,7 @@ fn history(args: CommandArgs) -> Result<OutputStream, ShellError> {
match clear {
Some(_) => {
// This is a NOOP, the logic to clear is handled in cli.rs
Ok(OutputStream::empty())
Ok(ActionStream::empty())
}
None => {
if let Ok(file) = File::open(path) {
@ -57,7 +57,7 @@ fn history(args: CommandArgs) -> Result<OutputStream, ShellError> {
Err(_) => None,
});
Ok(output.to_output_stream())
Ok(output.to_action_stream())
} else {
Err(ShellError::labeled_error(
"Could not open history",

View file

@ -6,6 +6,7 @@ use nu_errors::ShellError;
use nu_protocol::{
hir::CapturedBlock, hir::ClassifiedCommand, Signature, SyntaxShape, UntaggedValue,
};
use nu_stream::OutputStream;
pub struct If;
@ -110,11 +111,15 @@ fn if_command(raw_args: CommandArgs) -> Result<OutputStream, ShellError> {
};
context.scope.exit_scope();
result.map(|x| x.to_output_stream())
result
}
Err(e) => Ok(vec![Err(e)].into_iter().to_output_stream()),
Err(e) => Ok(OutputStream::from_stream(
vec![UntaggedValue::Error(e).into_untagged_value()].into_iter(),
)),
},
Err(e) => Ok(vec![Err(e)].into_iter().to_output_stream()),
Err(e) => Ok(OutputStream::from_stream(
vec![UntaggedValue::Error(e).into_untagged_value()].into_iter(),
)),
}
}

View file

@ -34,7 +34,7 @@ impl WholeStreamCommand for Command {
"Insert a new column with a given value."
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
insert(args)
}
@ -66,7 +66,7 @@ fn process_row(
input: Value,
mut value: Arc<Value>,
field: Arc<ColumnPath>,
) -> Result<OutputStream, ShellError> {
) -> Result<ActionStream, ShellError> {
let value = Arc::make_mut(&mut value);
Ok(match value {
@ -116,17 +116,17 @@ fn process_row(
value: UntaggedValue::Row(_),
..
} => match obj.insert_data_at_column_path(&field, result) {
Ok(v) => OutputStream::one(ReturnSuccess::value(v)),
Err(e) => OutputStream::one(Err(e)),
Ok(v) => ActionStream::one(ReturnSuccess::value(v)),
Err(e) => ActionStream::one(Err(e)),
},
_ => OutputStream::one(Err(ShellError::labeled_error(
_ => ActionStream::one(Err(ShellError::labeled_error(
"Unrecognized type in stream",
"original value",
block_tag.clone(),
))),
}
}
Err(e) => OutputStream::one(Err(e)),
Err(e) => ActionStream::one(Err(e)),
}
}
value => match input {
@ -139,18 +139,18 @@ fn process_row(
.unwrap_or_else(|| UntaggedValue::nothing().into_untagged_value())
.insert_data_at_column_path(&field, value.clone())
{
Ok(v) => OutputStream::one(ReturnSuccess::value(v)),
Err(e) => OutputStream::one(Err(e)),
Ok(v) => ActionStream::one(ReturnSuccess::value(v)),
Err(e) => ActionStream::one(Err(e)),
},
_ => match input.insert_data_at_column_path(&field, value.clone()) {
Ok(v) => OutputStream::one(ReturnSuccess::value(v)),
Err(e) => OutputStream::one(Err(e)),
Ok(v) => ActionStream::one(ReturnSuccess::value(v)),
Err(e) => ActionStream::one(Err(e)),
},
},
})
}
fn insert(raw_args: CommandArgs) -> Result<OutputStream, ShellError> {
fn insert(raw_args: CommandArgs) -> Result<ActionStream, ShellError> {
let context = Arc::new(EvaluationContext::from_args(&raw_args));
let (Arguments { column, value }, input) = raw_args.process()?;
let value = Arc::new(value);
@ -164,9 +164,9 @@ fn insert(raw_args: CommandArgs) -> Result<OutputStream, ShellError> {
match process_row(context, input, value, column) {
Ok(s) => s,
Err(e) => OutputStream::one(Err(e)),
Err(e) => ActionStream::one(Err(e)),
}
})
.flatten()
.to_output_stream())
.to_action_stream())
}

View file

@ -18,8 +18,8 @@ impl WholeStreamCommand for Command {
"Apply into function."
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
Ok(OutputStream::one(ReturnSuccess::value(
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
Ok(ActionStream::one(ReturnSuccess::value(
UntaggedValue::string(get_full_help(&Command, &args.scope)).into_value(Tag::unknown()),
)))
}

View file

@ -29,7 +29,7 @@ impl WholeStreamCommand for SubCommand {
"Convert value to integer"
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
into_int(args)
}
@ -85,7 +85,7 @@ impl WholeStreamCommand for SubCommand {
}
}
fn into_int(args: CommandArgs) -> Result<OutputStream, ShellError> {
fn into_int(args: CommandArgs) -> Result<ActionStream, ShellError> {
let (Arguments { rest: column_paths }, input) = args.process()?;
Ok(input
@ -104,7 +104,7 @@ fn into_int(args: CommandArgs) -> Result<OutputStream, ShellError> {
ReturnSuccess::value(ret)
}
})
.to_output_stream())
.to_action_stream())
}
pub fn action(input: &Value, tag: impl Into<Tag>) -> Result<Value, ShellError> {

View file

@ -28,7 +28,7 @@ impl WholeStreamCommand for Command {
"Keep the number of rows only."
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
keep(args)
}
@ -53,7 +53,7 @@ impl WholeStreamCommand for Command {
}
}
fn keep(args: CommandArgs) -> Result<OutputStream, ShellError> {
fn keep(args: CommandArgs) -> Result<ActionStream, ShellError> {
let (Arguments { rows }, input) = args.process()?;
let rows_desired = if let Some(quantity) = rows {
*quantity
@ -61,7 +61,7 @@ fn keep(args: CommandArgs) -> Result<OutputStream, ShellError> {
1
};
Ok(input.take(rows_desired).to_output_stream())
Ok(input.take(rows_desired).to_action_stream())
}
#[cfg(test)]

View file

@ -27,7 +27,7 @@ impl WholeStreamCommand for SubCommand {
"Keeps rows until the condition matches."
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
let ctx = Arc::new(EvaluationContext::from_args(&args));
let call_info = args.evaluate_once()?;
@ -93,7 +93,7 @@ impl WholeStreamCommand for SubCommand {
!matches!(result, Ok(ref v) if v.is_true())
})
.to_output_stream())
.to_action_stream())
}
}

View file

@ -26,7 +26,7 @@ impl WholeStreamCommand for SubCommand {
"Keeps rows while the condition matches."
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
let ctx = Arc::new(EvaluationContext::from_args(&args));
let call_info = args.evaluate_once()?;
@ -92,7 +92,7 @@ impl WholeStreamCommand for SubCommand {
matches!(result, Ok(ref v) if v.is_true())
})
.to_output_stream())
.to_action_stream())
}
}

View file

@ -48,7 +48,7 @@ impl WholeStreamCommand for Kill {
"Kill a process using the process id."
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
kill(args)
}
@ -73,7 +73,7 @@ impl WholeStreamCommand for Kill {
}
}
fn kill(args: CommandArgs) -> Result<OutputStream, ShellError> {
fn kill(args: CommandArgs) -> Result<ActionStream, ShellError> {
let (
KillArgs {
pid,
@ -136,7 +136,7 @@ fn kill(args: CommandArgs) -> Result<OutputStream, ShellError> {
cmd.status().expect("failed to execute shell command");
Ok(OutputStream::empty())
Ok(ActionStream::empty())
}
#[cfg(test)]

View file

@ -28,7 +28,7 @@ impl WholeStreamCommand for Last {
"Show only the last number of rows."
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
last(args)
}
@ -52,7 +52,7 @@ impl WholeStreamCommand for Last {
}
}
fn last(args: CommandArgs) -> Result<OutputStream, ShellError> {
fn last(args: CommandArgs) -> Result<ActionStream, ShellError> {
let (LastArgs { rows }, input) = args.process()?;
let v: Vec<_> = input.into_vec();
@ -70,7 +70,7 @@ fn last(args: CommandArgs) -> Result<OutputStream, ShellError> {
let iter = v.into_iter().skip(beginning_rows_to_skip);
Ok((iter).to_output_stream())
Ok((iter).to_action_stream())
}
#[cfg(test)]

View file

@ -28,7 +28,7 @@ impl WholeStreamCommand for Length {
"Show the total number of rows or items."
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
let tag = args.call_info.name_tag.clone();
let (LengthArgs { column }, input) = args.process()?;
@ -38,7 +38,7 @@ impl WholeStreamCommand for Length {
done: false,
tag,
}
.to_output_stream())
.to_action_stream())
}
fn examples(&self) -> Vec<Example> {

View file

@ -27,7 +27,7 @@ impl WholeStreamCommand for Let {
"Create a variable and give it a value."
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
letcmd(args)
}
@ -36,7 +36,7 @@ impl WholeStreamCommand for Let {
}
}
pub fn letcmd(args: CommandArgs) -> Result<OutputStream, ShellError> {
pub fn letcmd(args: CommandArgs) -> Result<ActionStream, ShellError> {
let tag = args.call_info.name_tag.clone();
let ctx = EvaluationContext::from_args(&args);
let args = args.evaluate_once()?;
@ -94,5 +94,5 @@ pub fn letcmd(args: CommandArgs) -> Result<OutputStream, ShellError> {
// variable should be set into.
ctx.scope.add_var(name, value);
Ok(OutputStream::empty())
Ok(ActionStream::empty())
}

View file

@ -38,7 +38,7 @@ impl WholeStreamCommand for LetEnv {
"Create an environment variable and give it a value."
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
set_env(args)
}
@ -47,7 +47,7 @@ impl WholeStreamCommand for LetEnv {
}
}
pub fn set_env(args: CommandArgs) -> Result<OutputStream, ShellError> {
pub fn set_env(args: CommandArgs) -> Result<ActionStream, ShellError> {
let tag = args.call_info.name_tag.clone();
let ctx = EvaluationContext::from_args(&args);
@ -99,5 +99,5 @@ pub fn set_env(args: CommandArgs) -> Result<OutputStream, ShellError> {
// variable should be set into.
ctx.scope.add_env_var(name, value);
Ok(OutputStream::empty())
Ok(ActionStream::empty())
}

View file

@ -19,7 +19,7 @@ impl WholeStreamCommand for Lines {
"Split single string into rows, one per line."
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
lines(args)
}
@ -42,7 +42,7 @@ fn ends_with_line_ending(st: &str) -> bool {
}
}
fn lines(args: CommandArgs) -> Result<OutputStream, ShellError> {
fn lines(args: CommandArgs) -> Result<ActionStream, ShellError> {
let leftover_string = Arc::new(Mutex::new(String::new()));
let args = args.evaluate_once()?;
let tag = args.name_tag();
@ -113,7 +113,7 @@ fn lines(args: CommandArgs) -> Result<OutputStream, ShellError> {
}
})
.flatten()
.to_output_stream())
.to_action_stream())
}
#[cfg(test)]

View file

@ -39,7 +39,7 @@ impl WholeStreamCommand for Ls {
"View the contents of the current or given path."
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
let name = args.call_info.name_tag.clone();
let ctrl_c = args.ctrl_c.clone();
let shell_manager = args.shell_manager.clone();

View file

@ -33,7 +33,7 @@ macro_rules! command {
fn command($args: EvaluatedCommandArgs, ( $($param_name),*, ): ( $($param_type),*, )) -> Result<OutputStream, ShellError> {
let output = $body;
Ok(output.to_output_stream())
Ok(output.to_action_stream())
}
let $args = $args.evaluate_once(registry)?;

View file

@ -18,7 +18,7 @@ impl WholeStreamCommand for SubCommand {
"Returns absolute values of a list of numbers"
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
let mapped = args.input.map(move |val| match val.value {
UntaggedValue::Primitive(Primitive::Int(val)) => {
UntaggedValue::int(val.magnitude().clone()).into()
@ -31,7 +31,7 @@ impl WholeStreamCommand for SubCommand {
}
other => abs_default(other),
});
Ok(OutputStream::from_input(mapped))
Ok(ActionStream::from_input(mapped))
}
fn examples(&self) -> Vec<Example> {

View file

@ -27,7 +27,7 @@ impl WholeStreamCommand for SubCommand {
"Finds the average of a list of numbers or tables"
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
run_with_function(args, average)
}

View file

@ -20,7 +20,7 @@ impl WholeStreamCommand for SubCommand {
"Applies the ceil function to a list of numbers"
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
let input = args.input;
run_with_numerical_functions_on_stream(input, ceil_big_int, ceil_big_decimal, ceil_default)

Some files were not shown because too many files have changed in this diff Show more