mirror of
https://github.com/nushell/nushell.git
synced 2025-04-15 16:58:19 +02:00
Split OutputStream into ActionStream/OutputStream (#3304)
* Split OutputStream into ActionStream/OutputStream * Fmt * Missed update * Cleanup helper names * Fmt
This commit is contained in:
parent
dbecbdccd4
commit
5f550a355b
@ -30,7 +30,7 @@ pub use nu_data::config;
|
|||||||
pub use nu_data::dict::TaggedListBuilder;
|
pub use nu_data::dict::TaggedListBuilder;
|
||||||
pub use nu_data::primitive;
|
pub use nu_data::primitive;
|
||||||
pub use nu_data::value;
|
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 nu_value_ext::ValueExt;
|
||||||
pub use num_traits::cast::ToPrimitive;
|
pub use num_traits::cast::ToPrimitive;
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ pub(crate) use nu_engine::Host;
|
|||||||
pub(crate) use nu_errors::ShellError;
|
pub(crate) use nu_errors::ShellError;
|
||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
pub(crate) use nu_protocol::outln;
|
pub(crate) use nu_protocol::outln;
|
||||||
pub(crate) use nu_stream::OutputStream;
|
pub(crate) use nu_stream::ActionStream;
|
||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
pub(crate) use nu_value_ext::ValueExt;
|
pub(crate) use nu_value_ext::ValueExt;
|
||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
@ -44,33 +44,16 @@ pub(crate) use std::sync::atomic::Ordering;
|
|||||||
|
|
||||||
#[allow(clippy::clippy::wrong_self_convention)]
|
#[allow(clippy::clippy::wrong_self_convention)]
|
||||||
pub trait FromInputStream {
|
pub trait FromInputStream {
|
||||||
fn from_input_stream(self) -> OutputStream;
|
fn from_input_stream(self) -> ActionStream;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> FromInputStream for T
|
impl<T> FromInputStream for T
|
||||||
where
|
where
|
||||||
T: Iterator<Item = nu_protocol::Value> + Send + Sync + 'static,
|
T: Iterator<Item = nu_protocol::Value> + Send + Sync + 'static,
|
||||||
{
|
{
|
||||||
fn from_input_stream(self) -> OutputStream {
|
fn from_input_stream(self) -> ActionStream {
|
||||||
OutputStream {
|
ActionStream {
|
||||||
values: Box::new(self.map(nu_protocol::ReturnSuccess::value)),
|
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())),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -5,6 +5,7 @@ use nu_errors::ShellError;
|
|||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
hir::CapturedBlock, hir::ClassifiedCommand, Signature, SyntaxShape, UntaggedValue,
|
hir::CapturedBlock, hir::ClassifiedCommand, Signature, SyntaxShape, UntaggedValue,
|
||||||
};
|
};
|
||||||
|
use nu_stream::ToActionStream;
|
||||||
|
|
||||||
pub struct Command;
|
pub struct Command;
|
||||||
|
|
||||||
@ -30,7 +31,7 @@ impl WholeStreamCommand for Command {
|
|||||||
"Find if the table rows matches the condition."
|
"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)
|
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 ctx = Arc::new(EvaluationContext::from_args(&args));
|
||||||
let tag = args.call_info.name_tag.clone();
|
let tag = args.call_info.name_tag.clone();
|
||||||
let (Arguments { block }, input) = args.process()?;
|
let (Arguments { block }, input) = args.process()?;
|
||||||
@ -117,7 +118,7 @@ fn all(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
Err(e) => Err(e),
|
Err(e) => Err(e),
|
||||||
}
|
}
|
||||||
})?
|
})?
|
||||||
.to_output_stream())
|
.to_action_stream())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -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 args = args.evaluate_once()?;
|
||||||
|
|
||||||
let code: Option<Result<Tagged<String>, ShellError>> = args.opt(0);
|
let code: Option<Result<Tagged<String>, ShellError>> = args.opt(0);
|
||||||
@ -130,7 +130,7 @@ Format: #
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
let output = format!("\x1b[{}", e.item);
|
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()),
|
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
|
//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
|
// OCS's need to end with a bell '\x07' char
|
||||||
let output = format!("\x1b]{};", o.item);
|
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()),
|
UntaggedValue::string(output).into_value(o.tag()),
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
@ -159,7 +159,7 @@ Format: #
|
|||||||
let ansi_code = str_to_ansi(&code.item);
|
let ansi_code = str_to_ansi(&code.item);
|
||||||
|
|
||||||
if let Some(output) = ansi_code {
|
if let Some(output) = ansi_code {
|
||||||
Ok(OutputStream::one(ReturnSuccess::value(
|
Ok(ActionStream::one(ReturnSuccess::value(
|
||||||
UntaggedValue::string(output).into_value(code.tag()),
|
UntaggedValue::string(output).into_value(code.tag()),
|
||||||
)))
|
)))
|
||||||
} else {
|
} else {
|
||||||
|
@ -31,7 +31,7 @@ impl WholeStreamCommand for SubCommand {
|
|||||||
"strip ansi escape sequences from string"
|
"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)
|
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 (Arguments { rest }, input) = args.process()?;
|
||||||
let column_paths: Vec<_> = rest;
|
let column_paths: Vec<_> = rest;
|
||||||
|
|
||||||
@ -65,7 +65,7 @@ fn operate(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
ReturnSuccess::value(ret)
|
ReturnSuccess::value(ret)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.to_output_stream())
|
.to_action_stream())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn action(input: &Value, tag: impl Into<Tag>) -> Result<Value, ShellError> {
|
fn action(input: &Value, tag: impl Into<Tag>) -> Result<Value, ShellError> {
|
||||||
|
@ -30,7 +30,7 @@ impl WholeStreamCommand for Command {
|
|||||||
"Find if the table rows matches the condition."
|
"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)
|
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 ctx = Arc::new(EvaluationContext::from_args(&args));
|
||||||
let tag = args.call_info.name_tag.clone();
|
let tag = args.call_info.name_tag.clone();
|
||||||
let (Arguments { block }, input) = args.process()?;
|
let (Arguments { block }, input) = args.process()?;
|
||||||
@ -117,7 +117,7 @@ fn any(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
Err(e) => Err(e),
|
Err(e) => Err(e),
|
||||||
}
|
}
|
||||||
})?
|
})?
|
||||||
.to_output_stream())
|
.to_action_stream())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -27,7 +27,7 @@ impl WholeStreamCommand for Command {
|
|||||||
"Append a row to the table."
|
"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 (Arguments { mut value }, input) = args.process()?;
|
||||||
|
|
||||||
let input: Vec<Value> = input.collect();
|
let input: Vec<Value> = input.collect();
|
||||||
@ -51,7 +51,7 @@ impl WholeStreamCommand for Command {
|
|||||||
.into_iter()
|
.into_iter()
|
||||||
.chain(vec![value])
|
.chain(vec![value])
|
||||||
.map(ReturnSuccess::value)
|
.map(ReturnSuccess::value)
|
||||||
.to_output_stream())
|
.to_action_stream())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn examples(&self) -> Vec<Example> {
|
fn examples(&self) -> Vec<Example> {
|
||||||
|
@ -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 {
|
fn signature(&self) -> Signature {
|
||||||
Signature::build("autoenv")
|
Signature::build("autoenv")
|
||||||
}
|
}
|
||||||
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
|
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||||
Ok(OutputStream::one(ReturnSuccess::value(
|
Ok(ActionStream::one(ReturnSuccess::value(
|
||||||
UntaggedValue::string(get_full_help(&Autoenv, &args.scope)).into_value(Tag::unknown()),
|
UntaggedValue::string(get_full_help(&Autoenv, &args.scope)).into_value(Tag::unknown()),
|
||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ impl WholeStreamCommand for AutoenvTrust {
|
|||||||
"Trust a .nu-env file in the current or given directory"
|
"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 tag = args.call_info.name_tag.clone();
|
||||||
let ctx = EvaluationContext::from_args(&args);
|
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");
|
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),
|
UntaggedValue::string(".nu-env trusted!").into_value(tag),
|
||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ impl WholeStreamCommand for AutoenvUnTrust {
|
|||||||
"Untrust a .nu-env file in the current or given directory"
|
"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 tag = args.call_info.name_tag.clone();
|
||||||
let ctx = EvaluationContext::from_args(&args);
|
let ctx = EvaluationContext::from_args(&args);
|
||||||
let file_to_untrust = match args.call_info.evaluate(&ctx)?.args.nth(0) {
|
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");
|
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),
|
UntaggedValue::string(".nu-env untrusted!").into_value(tag),
|
||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
|
@ -80,7 +80,7 @@ pub fn autoview(context: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
);
|
);
|
||||||
let command_args =
|
let command_args =
|
||||||
create_default_command_args(&context).with_input(stream);
|
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<_>>();
|
let _ = result.collect::<Vec<_>>();
|
||||||
} else {
|
} else {
|
||||||
out!("{}", s);
|
out!("{}", s);
|
||||||
@ -162,7 +162,7 @@ pub fn autoview(context: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
stream.push_back(x);
|
stream.push_back(x);
|
||||||
let command_args =
|
let command_args =
|
||||||
create_default_command_args(&context).with_input(stream);
|
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<_>>();
|
let _ = result.collect::<Vec<_>>();
|
||||||
} else {
|
} else {
|
||||||
use pretty_hex::*;
|
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 {
|
fn create_default_command_args(context: &RunnableContextWithoutInput) -> RawCommandArgs {
|
||||||
|
@ -47,7 +47,7 @@ impl WholeStreamCommand for Benchmark {
|
|||||||
"Runs a block and returns the time it took to execute it."
|
"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)
|
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 tag = raw_args.call_info.args.span;
|
||||||
let mut context = EvaluationContext::from_args(&raw_args);
|
let mut context = EvaluationContext::from_args(&raw_args);
|
||||||
let scope = raw_args.scope.clone();
|
let scope = raw_args.scope.clone();
|
||||||
@ -134,10 +134,10 @@ fn benchmark_output<T, Output>(
|
|||||||
passthrough: Option<CapturedBlock>,
|
passthrough: Option<CapturedBlock>,
|
||||||
tag: T,
|
tag: T,
|
||||||
context: &mut EvaluationContext,
|
context: &mut EvaluationContext,
|
||||||
) -> Result<OutputStream, ShellError>
|
) -> Result<ActionStream, ShellError>
|
||||||
where
|
where
|
||||||
T: Into<Tag> + Copy,
|
T: Into<Tag> + Copy,
|
||||||
Output: Into<OutputStream>,
|
Output: Into<ActionStream>,
|
||||||
{
|
{
|
||||||
let value = UntaggedValue::Row(Dictionary::from(
|
let value = UntaggedValue::Row(Dictionary::from(
|
||||||
indexmap
|
indexmap
|
||||||
@ -161,7 +161,7 @@ where
|
|||||||
|
|
||||||
Ok(block_output.into())
|
Ok(block_output.into())
|
||||||
} else {
|
} else {
|
||||||
let benchmark_output = OutputStream::one(value);
|
let benchmark_output = ActionStream::one(value);
|
||||||
Ok(benchmark_output)
|
Ok(benchmark_output)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ impl WholeStreamCommand for BuildString {
|
|||||||
"Builds a string from the arguments."
|
"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 tag = args.call_info.name_tag.clone();
|
||||||
let args = args.evaluate_once()?;
|
let args = args.evaluate_once()?;
|
||||||
let rest: Vec<Value> = args.rest(0)?;
|
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))
|
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),
|
UntaggedValue::string(output_string).into_value(tag),
|
||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ impl WholeStreamCommand for Cal {
|
|||||||
"Display a calendar."
|
"Display a calendar."
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
|
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||||
cal(args)
|
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 args = args.evaluate_once()?;
|
||||||
let mut calendar_vec_deque = VecDeque::new();
|
let mut calendar_vec_deque = VecDeque::new();
|
||||||
let tag = args.call_info.name_tag.clone();
|
let tag = args.call_info.name_tag.clone();
|
||||||
@ -101,7 +101,7 @@ pub fn cal(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
current_day_option,
|
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 {
|
fn get_invalid_year_shell_error(year_tag: &Tag) -> ShellError {
|
||||||
|
@ -24,7 +24,7 @@ impl WholeStreamCommand for Cd {
|
|||||||
"Change to a new path."
|
"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 name = args.call_info.name_tag.clone();
|
||||||
let shell_manager = args.shell_manager.clone();
|
let shell_manager = args.shell_manager.clone();
|
||||||
let (args, _): (CdArgs, _) = args.process()?;
|
let (args, _): (CdArgs, _) = args.process()?;
|
||||||
|
@ -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 args = args.evaluate_once()?;
|
||||||
|
|
||||||
let name: Tagged<String> = args.req(0)?;
|
let name: Tagged<String> = args.req(0)?;
|
||||||
@ -83,13 +83,13 @@ impl WholeStreamCommand for Char {
|
|||||||
Err(e) => return Err(e),
|
Err(e) => return Err(e),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(OutputStream::one(ReturnSuccess::value(
|
Ok(ActionStream::one(ReturnSuccess::value(
|
||||||
UntaggedValue::string(multi_byte).into_value(name.tag),
|
UntaggedValue::string(multi_byte).into_value(name.tag),
|
||||||
)))
|
)))
|
||||||
} else {
|
} else {
|
||||||
let decoded_char = string_to_unicode_char(&name.item, &name.tag);
|
let decoded_char = string_to_unicode_char(&name.item, &name.tag);
|
||||||
if let Ok(ch) = decoded_char {
|
if let Ok(ch) = decoded_char {
|
||||||
Ok(OutputStream::one(ReturnSuccess::value(
|
Ok(ActionStream::one(ReturnSuccess::value(
|
||||||
UntaggedValue::string(ch).into_value(name.tag()),
|
UntaggedValue::string(ch).into_value(name.tag()),
|
||||||
)))
|
)))
|
||||||
} else {
|
} else {
|
||||||
@ -103,7 +103,7 @@ impl WholeStreamCommand for Char {
|
|||||||
} else {
|
} else {
|
||||||
let special_character = str_to_character(&name.item);
|
let special_character = str_to_character(&name.item);
|
||||||
if let Some(output) = special_character {
|
if let Some(output) = special_character {
|
||||||
Ok(OutputStream::one(ReturnSuccess::value(
|
Ok(ActionStream::one(ReturnSuccess::value(
|
||||||
UntaggedValue::string(output).into_value(name.tag()),
|
UntaggedValue::string(output).into_value(name.tag()),
|
||||||
)))
|
)))
|
||||||
} else {
|
} else {
|
||||||
|
@ -19,14 +19,14 @@ impl WholeStreamCommand for Chart {
|
|||||||
"Displays charts."
|
"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() {
|
if args.scope.get_command("chart bar").is_none() {
|
||||||
return Err(ShellError::untagged_runtime_error(
|
return Err(ShellError::untagged_runtime_error(
|
||||||
"nu_plugin_chart not installed.",
|
"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()),
|
UntaggedValue::string(get_full_help(&Chart, &args.scope)).into_value(Tag::unknown()),
|
||||||
))))
|
))))
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ impl WholeStreamCommand for Clear {
|
|||||||
"Clears the terminal."
|
"Clears the terminal."
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run(&self, _: CommandArgs) -> Result<OutputStream, ShellError> {
|
fn run(&self, _: CommandArgs) -> Result<InputStream, ShellError> {
|
||||||
if cfg!(windows) {
|
if cfg!(windows) {
|
||||||
Command::new("cmd")
|
Command::new("cmd")
|
||||||
.args(&["/C", "cls"])
|
.args(&["/C", "cls"])
|
||||||
@ -31,7 +31,7 @@ impl WholeStreamCommand for Clear {
|
|||||||
.status()
|
.status()
|
||||||
.expect("failed to execute process");
|
.expect("failed to execute process");
|
||||||
}
|
}
|
||||||
Ok(OutputStream::empty())
|
Ok(InputStream::empty())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn examples(&self) -> Vec<Example> {
|
fn examples(&self) -> Vec<Example> {
|
||||||
|
@ -21,7 +21,7 @@ impl WholeStreamCommand for Clip {
|
|||||||
"Copy the contents of the pipeline to the copy/paste buffer."
|
"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)
|
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 input = args.input;
|
||||||
let name = args.call_info.name_tag.clone();
|
let name = args.call_info.name_tag;
|
||||||
let values: Vec<Value> = input.collect();
|
let values: Vec<Value> = input.collect();
|
||||||
|
|
||||||
if let Ok(mut clip_context) = Clipboard::new() {
|
if let Ok(mut clip_context) = Clipboard::new() {
|
||||||
@ -88,7 +88,7 @@ pub fn clip(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
name,
|
name,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
Ok(OutputStream::empty())
|
Ok(ActionStream::empty())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -25,7 +25,7 @@ impl WholeStreamCommand for Compact {
|
|||||||
"Creates a table with non-empty rows."
|
"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)
|
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()?;
|
let (CompactArgs { rest: columns }, input) = args.process()?;
|
||||||
Ok(input
|
Ok(input
|
||||||
.filter_map(move |item| {
|
.filter_map(move |item| {
|
||||||
@ -67,7 +67,7 @@ pub fn compact(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.to_output_stream())
|
.to_action_stream())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -18,7 +18,7 @@ impl WholeStreamCommand for SubCommand {
|
|||||||
"clear the config"
|
"clear the config"
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
|
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||||
clear(args)
|
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 ctx = EvaluationContext::from_args(&args);
|
||||||
|
|
||||||
let result = if let Some(global_cfg) = &mut args.configs.lock().global_config {
|
let result = if let Some(global_cfg) = &mut args.configs.lock().global_config {
|
||||||
global_cfg.vars.clear();
|
global_cfg.vars.clear();
|
||||||
global_cfg.write()?;
|
global_cfg.write()?;
|
||||||
ctx.reload_config(global_cfg)?;
|
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),
|
UntaggedValue::Row(global_cfg.vars.clone().into()).into_value(args.call_info.name_tag),
|
||||||
)))
|
)))
|
||||||
} else {
|
} else {
|
||||||
@ -46,7 +46,7 @@ pub fn clear(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
crate::commands::config::err_no_global_cfg_present(),
|
crate::commands::config::err_no_global_cfg_present(),
|
||||||
))]
|
))]
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.to_output_stream())
|
.to_action_stream())
|
||||||
};
|
};
|
||||||
|
|
||||||
result
|
result
|
||||||
|
@ -3,7 +3,7 @@ use nu_engine::CommandArgs;
|
|||||||
use nu_engine::WholeStreamCommand;
|
use nu_engine::WholeStreamCommand;
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_protocol::{ReturnSuccess, Signature, UntaggedValue};
|
use nu_protocol::{ReturnSuccess, Signature, UntaggedValue};
|
||||||
use nu_stream::OutputStream;
|
use nu_stream::ActionStream;
|
||||||
|
|
||||||
pub struct Command;
|
pub struct Command;
|
||||||
|
|
||||||
@ -20,7 +20,7 @@ impl WholeStreamCommand for Command {
|
|||||||
"Configuration management."
|
"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;
|
let name = args.call_info.name_tag;
|
||||||
|
|
||||||
if let Some(global_cfg) = &args.configs.lock().global_config {
|
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),
|
UntaggedValue::Row(result.into()).into_value(name),
|
||||||
)]
|
)]
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.to_output_stream())
|
.to_action_stream())
|
||||||
} else {
|
} else {
|
||||||
Ok(vec![ReturnSuccess::value(UntaggedValue::Error(
|
Ok(vec![ReturnSuccess::value(UntaggedValue::Error(
|
||||||
crate::commands::config::err_no_global_cfg_present(),
|
crate::commands::config::err_no_global_cfg_present(),
|
||||||
))]
|
))]
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.to_output_stream())
|
.to_action_stream())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ impl WholeStreamCommand for SubCommand {
|
|||||||
"Gets a value from the config"
|
"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)
|
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 name = args.call_info.name_tag.clone();
|
||||||
let ctx = EvaluationContext::from_args(&args);
|
let ctx = EvaluationContext::from_args(&args);
|
||||||
|
|
||||||
@ -53,15 +53,15 @@ pub fn get(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
Value {
|
Value {
|
||||||
value: UntaggedValue::Table(list),
|
value: UntaggedValue::Table(list),
|
||||||
..
|
..
|
||||||
} => list.into_iter().to_output_stream(),
|
} => list.into_iter().to_action_stream(),
|
||||||
x => OutputStream::one(ReturnSuccess::value(x)),
|
x => ActionStream::one(ReturnSuccess::value(x)),
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
Ok(vec![ReturnSuccess::value(UntaggedValue::Error(
|
Ok(vec![ReturnSuccess::value(UntaggedValue::Error(
|
||||||
crate::commands::config::err_no_global_cfg_present(),
|
crate::commands::config::err_no_global_cfg_present(),
|
||||||
))]
|
))]
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.to_output_stream())
|
.to_action_stream())
|
||||||
};
|
};
|
||||||
|
|
||||||
result
|
result
|
||||||
|
@ -18,7 +18,7 @@ impl WholeStreamCommand for SubCommand {
|
|||||||
"return the path to the config file"
|
"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)
|
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 {
|
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())),
|
UntaggedValue::Primitive(Primitive::FilePath(global_cfg.file_path.clone())),
|
||||||
)))
|
)))
|
||||||
} else {
|
} else {
|
||||||
@ -41,6 +41,6 @@ pub fn path(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
crate::commands::config::err_no_global_cfg_present(),
|
crate::commands::config::err_no_global_cfg_present(),
|
||||||
))]
|
))]
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.to_output_stream())
|
.to_action_stream())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ impl WholeStreamCommand for SubCommand {
|
|||||||
"Removes a value from the config"
|
"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)
|
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 ctx = EvaluationContext::from_args(&args);
|
||||||
let (Arguments { remove }, _) = args.process()?;
|
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()),
|
UntaggedValue::row(global_cfg.vars.clone()).into_value(remove.tag()),
|
||||||
)]
|
)]
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.to_output_stream())
|
.to_action_stream())
|
||||||
} else {
|
} else {
|
||||||
Err(ShellError::labeled_error(
|
Err(ShellError::labeled_error(
|
||||||
"Key does not exist in config",
|
"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(),
|
crate::commands::config::err_no_global_cfg_present(),
|
||||||
))]
|
))]
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.to_output_stream())
|
.to_action_stream())
|
||||||
};
|
};
|
||||||
|
|
||||||
result
|
result
|
||||||
|
@ -26,7 +26,7 @@ impl WholeStreamCommand for SubCommand {
|
|||||||
"Sets a value in the config"
|
"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)
|
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 name = args.call_info.name_tag.clone();
|
||||||
let ctx = EvaluationContext::from_args(&args);
|
let ctx = EvaluationContext::from_args(&args);
|
||||||
let (
|
let (
|
||||||
@ -85,11 +85,11 @@ pub fn set(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
global_cfg.write()?;
|
global_cfg.write()?;
|
||||||
ctx.reload_config(global_cfg)?;
|
ctx.reload_config(global_cfg)?;
|
||||||
|
|
||||||
Ok(OutputStream::one(ReturnSuccess::value(
|
Ok(ActionStream::one(ReturnSuccess::value(
|
||||||
UntaggedValue::row(global_cfg.vars.clone()).into_value(name),
|
UntaggedValue::row(global_cfg.vars.clone()).into_value(name),
|
||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
Ok(_) => Ok(OutputStream::empty()),
|
Ok(_) => Ok(ActionStream::empty()),
|
||||||
Err(reason) => Err(reason),
|
Err(reason) => Err(reason),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -97,7 +97,7 @@ pub fn set(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
crate::commands::config::err_no_global_cfg_present(),
|
crate::commands::config::err_no_global_cfg_present(),
|
||||||
))]
|
))]
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.to_output_stream())
|
.to_action_stream())
|
||||||
};
|
};
|
||||||
|
|
||||||
result
|
result
|
||||||
|
@ -28,7 +28,7 @@ impl WholeStreamCommand for SubCommand {
|
|||||||
"Sets a value in the config"
|
"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)
|
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 name = args.call_info.name_tag.clone();
|
||||||
let ctx = EvaluationContext::from_args(&args);
|
let ctx = EvaluationContext::from_args(&args);
|
||||||
let (Arguments { set_into: v }, input) = args.process()?;
|
let (Arguments { set_into: v }, input) = args.process()?;
|
||||||
@ -71,7 +71,7 @@ pub fn set_into(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
global_cfg.write()?;
|
global_cfg.write()?;
|
||||||
ctx.reload_config(global_cfg)?;
|
ctx.reload_config(global_cfg)?;
|
||||||
|
|
||||||
Ok(OutputStream::one(ReturnSuccess::value(
|
Ok(ActionStream::one(ReturnSuccess::value(
|
||||||
UntaggedValue::row(global_cfg.vars.clone()).into_value(name),
|
UntaggedValue::row(global_cfg.vars.clone()).into_value(name),
|
||||||
)))
|
)))
|
||||||
} else {
|
} else {
|
||||||
@ -79,7 +79,7 @@ pub fn set_into(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
crate::commands::config::err_no_global_cfg_present(),
|
crate::commands::config::err_no_global_cfg_present(),
|
||||||
))]
|
))]
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.to_output_stream())
|
.to_action_stream())
|
||||||
};
|
};
|
||||||
|
|
||||||
result
|
result
|
||||||
|
@ -25,7 +25,7 @@ impl WholeStreamCommand for Cpy {
|
|||||||
"Copy files."
|
"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 shell_manager = args.shell_manager.clone();
|
||||||
let name = args.call_info.name_tag.clone();
|
let name = args.call_info.name_tag.clone();
|
||||||
let (args, _) = args.process()?;
|
let (args, _) = args.process()?;
|
||||||
|
@ -18,8 +18,8 @@ impl WholeStreamCommand for Command {
|
|||||||
"Apply date function."
|
"Apply date function."
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
|
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||||
Ok(OutputStream::one(ReturnSuccess::value(
|
Ok(ActionStream::one(ReturnSuccess::value(
|
||||||
UntaggedValue::string(get_full_help(&Command, &args.scope)).into_value(Tag::unknown()),
|
UntaggedValue::string(get_full_help(&Command, &args.scope)).into_value(Tag::unknown()),
|
||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ impl WholeStreamCommand for Date {
|
|||||||
"Format a given date using the given format string."
|
"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)
|
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 tag = args.call_info.name_tag.clone();
|
||||||
let (FormatArgs { format, table }, input) = args.process()?;
|
let (FormatArgs { format, table }, input) = args.process()?;
|
||||||
|
|
||||||
@ -91,7 +91,7 @@ pub fn format(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
&tag,
|
&tag,
|
||||||
)),
|
)),
|
||||||
})
|
})
|
||||||
.to_output_stream())
|
.to_action_stream())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -20,7 +20,7 @@ impl WholeStreamCommand for Date {
|
|||||||
"List supported time zones."
|
"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)
|
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 args = args.evaluate_once()?;
|
||||||
let tag = args.call_info.name_tag.clone();
|
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)]
|
#[cfg(test)]
|
||||||
|
@ -19,12 +19,12 @@ impl WholeStreamCommand for Date {
|
|||||||
"Get the current 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)
|
now(args)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn now(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
pub fn now(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||||
let args = args.evaluate_once()?;
|
let args = args.evaluate_once()?;
|
||||||
let tag = args.call_info.name_tag.clone();
|
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);
|
let value = UntaggedValue::date(now.with_timezone(now.offset())).into_value(&tag);
|
||||||
|
|
||||||
Ok(OutputStream::one(value))
|
Ok(ActionStream::one(value))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -20,7 +20,7 @@ impl WholeStreamCommand for Date {
|
|||||||
"Print the date in a structured table."
|
"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)
|
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 args = args.evaluate_once()?;
|
||||||
let tag = args.call_info.name_tag.clone();
|
let tag = args.call_info.name_tag.clone();
|
||||||
let input = args.input;
|
let input = args.input;
|
||||||
@ -87,7 +87,7 @@ fn to_table(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
&tag,
|
&tag,
|
||||||
)),
|
)),
|
||||||
})
|
})
|
||||||
.to_output_stream())
|
.to_action_stream())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -33,7 +33,7 @@ impl WholeStreamCommand for Date {
|
|||||||
"Use 'date list-timezone' to list all supported time zones."
|
"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)
|
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 tag = args.call_info.name_tag.clone();
|
||||||
let (DateToTimeZoneArgs { timezone }, input) = args.process()?;
|
let (DateToTimeZoneArgs { timezone }, input) = args.process()?;
|
||||||
|
|
||||||
@ -85,7 +85,7 @@ fn to_timezone(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
&tag,
|
&tag,
|
||||||
)),
|
)),
|
||||||
})
|
})
|
||||||
.to_output_stream())
|
.to_action_stream())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn error_message(err: ParseErrorKind) -> &'static str {
|
fn error_message(err: ParseErrorKind) -> &'static str {
|
||||||
|
@ -21,7 +21,7 @@ impl WholeStreamCommand for Date {
|
|||||||
"return the current date in utc."
|
"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)
|
utc(args)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,12 +23,12 @@ impl WholeStreamCommand for Debug {
|
|||||||
"Print the Rust debug representation of the values."
|
"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)
|
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()?;
|
let (DebugArgs { raw }, input) = args.process()?;
|
||||||
Ok(input
|
Ok(input
|
||||||
.map(move |v| {
|
.map(move |v| {
|
||||||
@ -40,7 +40,7 @@ fn debug_value(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
ReturnSuccess::debug_value(v)
|
ReturnSuccess::debug_value(v)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.to_output_stream())
|
.to_action_stream())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -34,11 +34,11 @@ impl WholeStreamCommand for Def {
|
|||||||
"Create a command and set it to a definition."
|
"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
|
// Currently, we don't do anything here because we should have already
|
||||||
// installed the definition as we entered the scope
|
// installed the definition as we entered the scope
|
||||||
// We just create a command so that we can get proper coloring
|
// We just create a command so that we can get proper coloring
|
||||||
Ok(OutputStream::empty())
|
Ok(ActionStream::empty())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn examples(&self) -> Vec<Example> {
|
fn examples(&self) -> Vec<Example> {
|
||||||
|
@ -32,7 +32,7 @@ impl WholeStreamCommand for Default {
|
|||||||
"Sets a default row's column if missing."
|
"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)
|
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()?;
|
let (DefaultArgs { column, value }, input) = args.process()?;
|
||||||
|
|
||||||
Ok(input
|
Ok(input
|
||||||
@ -67,7 +67,7 @@ fn default(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
ReturnSuccess::value(item)
|
ReturnSuccess::value(item)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.to_output_stream())
|
.to_action_stream())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -22,12 +22,12 @@ impl WholeStreamCommand for Describe {
|
|||||||
"Describes the objects in the stream."
|
"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)
|
describe(args)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn describe(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
pub fn describe(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||||
Ok(args
|
Ok(args
|
||||||
.input
|
.input
|
||||||
.map(|row| {
|
.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)),
|
UntaggedValue::string(name).into_value(Tag::unknown_anchor(row.tag.span)),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.to_output_stream())
|
.to_action_stream())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -31,7 +31,7 @@ impl WholeStreamCommand for Do {
|
|||||||
"Runs a block, optionally ignoring errors."
|
"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)
|
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 external_redirection = raw_args.call_info.args.external_redirection;
|
||||||
|
|
||||||
let context = EvaluationContext::from_args(&raw_args);
|
let context = EvaluationContext::from_args(&raw_args);
|
||||||
@ -96,12 +96,12 @@ fn do_(raw_args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
Ok(mut stream) => {
|
Ok(mut stream) => {
|
||||||
let output = stream.drain_vec();
|
let output = stream.drain_vec();
|
||||||
context.clear_errors();
|
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 {
|
} else {
|
||||||
result.map(|x| x.to_output_stream())
|
result.map(|x| x.to_action_stream())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ impl WholeStreamCommand for SubCommand {
|
|||||||
"Remove the last number of columns. If you want to remove columns by name, try 'reject'."
|
"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)
|
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 (Arguments { columns }, input) = args.process()?;
|
||||||
|
|
||||||
let to_drop = if let Some(quantity) = columns {
|
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())
|
select_fields(&item, descs, item.tag())
|
||||||
})
|
})
|
||||||
.map(ReturnSuccess::value)
|
.map(ReturnSuccess::value)
|
||||||
.to_output_stream())
|
.to_action_stream())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -28,7 +28,7 @@ impl WholeStreamCommand for Command {
|
|||||||
"Remove the last number of rows or columns."
|
"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)
|
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 (Arguments { rows }, input) = args.process()?;
|
||||||
let v: Vec<_> = input.into_vec();
|
let v: Vec<_> = input.into_vec();
|
||||||
|
|
||||||
@ -62,7 +62,7 @@ fn drop(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Ok(if rows_to_drop == 0 {
|
Ok(if rows_to_drop == 0 {
|
||||||
v.into_iter().to_output_stream()
|
v.into_iter().to_action_stream()
|
||||||
} else {
|
} else {
|
||||||
let k = if v.len() < rows_to_drop {
|
let k = if v.len() < rows_to_drop {
|
||||||
0
|
0
|
||||||
@ -72,6 +72,6 @@ fn drop(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
|
|
||||||
let iter = v.into_iter().take(k);
|
let iter = v.into_iter().take(k);
|
||||||
|
|
||||||
iter.to_output_stream()
|
iter.to_action_stream()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,7 @@ impl WholeStreamCommand for Du {
|
|||||||
"Find disk usage sizes of specified items."
|
"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)
|
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 tag = args.call_info.name_tag.clone();
|
||||||
let ctrl_c = args.ctrl_c.clone();
|
let ctrl_c = args.ctrl_c.clone();
|
||||||
let ctrl_c_copy = 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)],
|
Err(e) => vec![Err(e)],
|
||||||
})
|
})
|
||||||
.interruptible(ctrl_c_copy)
|
.interruptible(ctrl_c_copy)
|
||||||
.to_output_stream())
|
.to_action_stream())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn glob_err_into(e: GlobError) -> ShellError {
|
fn glob_err_into(e: GlobError) -> ShellError {
|
||||||
|
@ -90,7 +90,7 @@ pub fn process_row(
|
|||||||
|
|
||||||
context.scope.exit_scope();
|
context.scope.exit_scope();
|
||||||
|
|
||||||
Ok(result?.to_output_stream())
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn make_indexed_item(index: usize, item: Value) -> Value {
|
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) {
|
match process_row(block, context, row) {
|
||||||
Ok(s) => s,
|
Ok(s) => s,
|
||||||
Err(e) => OutputStream::one(Err(e)),
|
Err(e) => OutputStream::one(Value::error(e)),
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.flatten()
|
.flatten()
|
||||||
@ -135,7 +135,7 @@ fn each(raw_args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
|
|
||||||
match process_row(block, context, input) {
|
match process_row(block, context, input) {
|
||||||
Ok(s) => s,
|
Ok(s) => s,
|
||||||
Err(e) => OutputStream::one(Err(e)),
|
Err(e) => OutputStream::one(Value::error(e)),
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.flatten()
|
.flatten()
|
||||||
|
@ -2,9 +2,7 @@ use crate::commands::each::process_row;
|
|||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use nu_engine::WholeStreamCommand;
|
use nu_engine::WholeStreamCommand;
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_protocol::{
|
use nu_protocol::{hir::CapturedBlock, Signature, SyntaxShape, UntaggedValue, Value};
|
||||||
hir::CapturedBlock, ReturnSuccess, Signature, SyntaxShape, UntaggedValue, Value,
|
|
||||||
};
|
|
||||||
use nu_source::Tagged;
|
use nu_source::Tagged;
|
||||||
use serde::Deserialize;
|
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 context = Arc::new(EvaluationContext::from_args(&raw_args));
|
||||||
let (each_args, input): (EachGroupArgs, _) = raw_args.process()?;
|
let (each_args, input): (EachGroupArgs, _) = raw_args.process()?;
|
||||||
let block = Arc::new(Box::new(each_args.block));
|
let block = Arc::new(Box::new(each_args.block));
|
||||||
@ -56,7 +54,7 @@ impl WholeStreamCommand for EachGroup {
|
|||||||
input,
|
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
|
// If it returned multiple values, we need to put them into a table and
|
||||||
// return that.
|
// return that.
|
||||||
let result = vec.into_iter().collect::<Result<Vec<ReturnSuccess>, _>>();
|
OutputStream::one(UntaggedValue::Table(vec).into_untagged_value())
|
||||||
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())))
|
|
||||||
}
|
}
|
||||||
Err(e) => OutputStream::one(Err(e)),
|
Err(e) => OutputStream::one(Value::error(e)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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 context = Arc::new(EvaluationContext::from_args(&raw_args));
|
||||||
let (each_args, mut input): (EachWindowArgs, _) = raw_args.process()?;
|
let (each_args, mut input): (EachWindowArgs, _) = raw_args.process()?;
|
||||||
let block = Arc::new(Box::new(each_args.block));
|
let block = Arc::new(Box::new(each_args.block));
|
||||||
@ -83,7 +83,7 @@ impl WholeStreamCommand for EachWindow {
|
|||||||
})
|
})
|
||||||
.filter_map(|x| x)
|
.filter_map(|x| x)
|
||||||
.flatten()
|
.flatten()
|
||||||
.to_output_stream())
|
.to_action_stream())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,9 +3,7 @@ use bigdecimal::Zero;
|
|||||||
use nu_engine::WholeStreamCommand;
|
use nu_engine::WholeStreamCommand;
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_protocol::hir::Operator;
|
use nu_protocol::hir::Operator;
|
||||||
use nu_protocol::{
|
use nu_protocol::{Primitive, Range, RangeInclusion, Signature, SyntaxShape, UntaggedValue, Value};
|
||||||
Primitive, Range, RangeInclusion, ReturnSuccess, Signature, SyntaxShape, UntaggedValue, Value,
|
|
||||||
};
|
|
||||||
|
|
||||||
pub struct Echo;
|
pub struct Echo;
|
||||||
|
|
||||||
@ -22,7 +20,7 @@ impl WholeStreamCommand for Echo {
|
|||||||
"Echo the arguments back to the user."
|
"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)
|
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 args = args.evaluate_once()?;
|
||||||
let rest: Vec<Value> = args.rest(0)?;
|
let rest: Vec<Value> = args.rest(0)?;
|
||||||
|
|
||||||
let stream = rest.into_iter().map(|i| match i.as_string() {
|
let stream = rest.into_iter().map(|i| match i.as_string() {
|
||||||
Ok(s) => OutputStream::one(Ok(ReturnSuccess::Value(
|
Ok(s) => InputStream::one(UntaggedValue::string(s).into_value(i.tag.clone())),
|
||||||
UntaggedValue::string(s).into_value(i.tag.clone()),
|
|
||||||
))),
|
|
||||||
_ => match i {
|
_ => match i {
|
||||||
Value {
|
Value {
|
||||||
value: UntaggedValue::Table(table),
|
value: UntaggedValue::Table(table),
|
||||||
..
|
..
|
||||||
} => table
|
} => InputStream::from_stream(table.into_iter()),
|
||||||
.into_iter()
|
|
||||||
.map(ReturnSuccess::value)
|
|
||||||
.to_output_stream(),
|
|
||||||
Value {
|
Value {
|
||||||
value: UntaggedValue::Primitive(Primitive::Range(range)),
|
value: UntaggedValue::Primitive(Primitive::Range(range)),
|
||||||
tag,
|
tag,
|
||||||
} => RangeIterator::new(*range, tag).to_output_stream(),
|
} => InputStream::from_stream(RangeIterator::new(*range, tag)),
|
||||||
x => OutputStream::one(Ok(ReturnSuccess::Value(x))),
|
x => InputStream::one(x),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
Ok(stream.flatten().to_output_stream())
|
Ok(InputStream::from_stream(stream.flatten()))
|
||||||
}
|
}
|
||||||
|
|
||||||
struct RangeIterator {
|
struct RangeIterator {
|
||||||
@ -77,6 +70,7 @@ struct RangeIterator {
|
|||||||
moves_up: bool,
|
moves_up: bool,
|
||||||
one: UntaggedValue,
|
one: UntaggedValue,
|
||||||
negative_one: UntaggedValue,
|
negative_one: UntaggedValue,
|
||||||
|
done: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RangeIterator {
|
impl RangeIterator {
|
||||||
@ -99,14 +93,18 @@ impl RangeIterator {
|
|||||||
is_end_inclusive: matches!(range.to.1, RangeInclusion::Inclusive),
|
is_end_inclusive: matches!(range.to.1, RangeInclusion::Inclusive),
|
||||||
one: UntaggedValue::int(1),
|
one: UntaggedValue::int(1),
|
||||||
negative_one: UntaggedValue::int(-1),
|
negative_one: UntaggedValue::int(-1),
|
||||||
|
done: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Iterator for RangeIterator {
|
impl Iterator for RangeIterator {
|
||||||
type Item = Result<ReturnSuccess, ShellError>;
|
type Item = Value;
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
use std::cmp::Ordering;
|
use std::cmp::Ordering;
|
||||||
|
if self.done {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
let ordering = if self.end == UntaggedValue::Primitive(Primitive::Nothing) {
|
let ordering = if self.end == UntaggedValue::Primitive(Primitive::Nothing) {
|
||||||
Ordering::Less
|
Ordering::Less
|
||||||
@ -129,11 +127,15 @@ impl Iterator for RangeIterator {
|
|||||||
UntaggedValue::Primitive(Primitive::Decimal(y)),
|
UntaggedValue::Primitive(Primitive::Decimal(y)),
|
||||||
) => (BigDecimal::zero() + x).cmp(y),
|
) => (BigDecimal::zero() + x).cmp(y),
|
||||||
_ => {
|
_ => {
|
||||||
return Some(Err(ShellError::labeled_error(
|
self.done = true;
|
||||||
"Cannot create range",
|
return Some(
|
||||||
"unsupported range",
|
UntaggedValue::Error(ShellError::labeled_error(
|
||||||
self.tag.span,
|
"Cannot create range",
|
||||||
)))
|
"unsupported range",
|
||||||
|
self.tag.span,
|
||||||
|
))
|
||||||
|
.into_untagged_value(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -147,15 +149,19 @@ impl Iterator for RangeIterator {
|
|||||||
Ok(result) => result,
|
Ok(result) => result,
|
||||||
|
|
||||||
Err((left_type, right_type)) => {
|
Err((left_type, right_type)) => {
|
||||||
return Some(Err(ShellError::coerce_error(
|
self.done = true;
|
||||||
left_type.spanned(self.tag.span),
|
return Some(
|
||||||
right_type.spanned(self.tag.span),
|
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);
|
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
|
} else if !self.moves_up
|
||||||
&& (ordering == Ordering::Greater
|
&& (ordering == Ordering::Greater
|
||||||
|| self.is_end_inclusive && ordering == Ordering::Equal)
|
|| self.is_end_inclusive && ordering == Ordering::Equal)
|
||||||
@ -166,15 +172,19 @@ impl Iterator for RangeIterator {
|
|||||||
let mut next = match next_value {
|
let mut next = match next_value {
|
||||||
Ok(result) => result,
|
Ok(result) => result,
|
||||||
Err((left_type, right_type)) => {
|
Err((left_type, right_type)) => {
|
||||||
return Some(Err(ShellError::coerce_error(
|
self.done = true;
|
||||||
left_type.spanned(self.tag.span),
|
return Some(
|
||||||
right_type.spanned(self.tag.span),
|
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);
|
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 {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ impl WholeStreamCommand for Command {
|
|||||||
"Check for empty values."
|
"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)
|
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 tag = args.call_info.name_tag.clone();
|
||||||
let name_tag = Arc::new(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));
|
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) {
|
match process_row(context, input, block, columns, tag) {
|
||||||
Ok(s) => s,
|
Ok(s) => s,
|
||||||
Err(e) => OutputStream::one(Err(e)),
|
Err(e) => ActionStream::one(Err(e)),
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.flatten()
|
.flatten()
|
||||||
.to_output_stream());
|
.to_action_stream());
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(input
|
Ok(input
|
||||||
@ -116,11 +116,11 @@ fn is_empty(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
|
|
||||||
match process_row(context, input, block, columns, tag) {
|
match process_row(context, input, block, columns, tag) {
|
||||||
Ok(s) => s,
|
Ok(s) => s,
|
||||||
Err(e) => OutputStream::one(Err(e)),
|
Err(e) => ActionStream::one(Err(e)),
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.flatten()
|
.flatten()
|
||||||
.to_output_stream())
|
.to_action_stream())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process_row(
|
fn process_row(
|
||||||
@ -129,7 +129,7 @@ fn process_row(
|
|||||||
default_block: Arc<Option<Box<CapturedBlock>>>,
|
default_block: Arc<Option<Box<CapturedBlock>>>,
|
||||||
column_paths: Vec<ColumnPath>,
|
column_paths: Vec<ColumnPath>,
|
||||||
tag: Arc<Tag>,
|
tag: Arc<Tag>,
|
||||||
) -> Result<OutputStream, ShellError> {
|
) -> Result<ActionStream, ShellError> {
|
||||||
let _tag = &*tag;
|
let _tag = &*tag;
|
||||||
let mut out = Arc::new(None);
|
let mut out = Arc::new(None);
|
||||||
let results = Arc::make_mut(&mut out);
|
let results = Arc::make_mut(&mut out);
|
||||||
@ -178,7 +178,7 @@ fn process_row(
|
|||||||
ref tag,
|
ref tag,
|
||||||
} => {
|
} => {
|
||||||
if column_paths.is_empty() {
|
if column_paths.is_empty() {
|
||||||
Ok(OutputStream::one(ReturnSuccess::value({
|
Ok(ActionStream::one(ReturnSuccess::value({
|
||||||
let is_empty = input.is_empty();
|
let is_empty = input.is_empty();
|
||||||
|
|
||||||
if default_block.is_some() {
|
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() {
|
if other.is_empty() {
|
||||||
results
|
results
|
||||||
.clone()
|
.clone()
|
||||||
|
@ -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"#
|
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)
|
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 scope = raw_args.scope.clone();
|
||||||
let shell_manager = raw_args.shell_manager.clone();
|
let shell_manager = raw_args.shell_manager.clone();
|
||||||
let head = raw_args.call_info.args.head.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();
|
let location_string = location.display().to_string();
|
||||||
|
|
||||||
if location.is_dir() {
|
if location.is_dir() {
|
||||||
Ok(OutputStream::one(ReturnSuccess::action(
|
Ok(ActionStream::one(ReturnSuccess::action(
|
||||||
CommandAction::EnterShell(location_string),
|
CommandAction::EnterShell(location_string),
|
||||||
)))
|
)))
|
||||||
} else {
|
} else {
|
||||||
@ -129,8 +129,8 @@ fn enter(raw_args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
scope,
|
scope,
|
||||||
};
|
};
|
||||||
let tag = tagged_contents.tag.clone();
|
let tag = tagged_contents.tag.clone();
|
||||||
let mut result =
|
let mut result = converter
|
||||||
converter.run(new_args.with_input(vec![tagged_contents]))?;
|
.run_with_actions(new_args.with_input(vec![tagged_contents]))?;
|
||||||
let result_vec: Vec<Result<ReturnSuccess, ShellError>> = result.drain_vec();
|
let result_vec: Vec<Result<ReturnSuccess, ShellError>> = result.drain_vec();
|
||||||
Ok(result_vec
|
Ok(result_vec
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@ -143,19 +143,19 @@ fn enter(raw_args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
),
|
),
|
||||||
x => x,
|
x => x,
|
||||||
})
|
})
|
||||||
.to_output_stream())
|
.to_action_stream())
|
||||||
} else {
|
} else {
|
||||||
Ok(OutputStream::one(ReturnSuccess::action(
|
Ok(ActionStream::one(ReturnSuccess::action(
|
||||||
CommandAction::EnterValueShell(tagged_contents),
|
CommandAction::EnterValueShell(tagged_contents),
|
||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Ok(OutputStream::one(ReturnSuccess::action(
|
Ok(ActionStream::one(ReturnSuccess::action(
|
||||||
CommandAction::EnterValueShell(tagged_contents),
|
CommandAction::EnterValueShell(tagged_contents),
|
||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => Ok(OutputStream::one(ReturnSuccess::action(
|
_ => Ok(ActionStream::one(ReturnSuccess::action(
|
||||||
CommandAction::EnterValueShell(tagged_contents),
|
CommandAction::EnterValueShell(tagged_contents),
|
||||||
))),
|
))),
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ impl WholeStreamCommand for Every {
|
|||||||
"Show (or skip) every n-th row, starting from the first one."
|
"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)
|
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 (EveryArgs { stride, skip }, input) = args.process()?;
|
||||||
|
|
||||||
let stride = stride.item;
|
let stride = stride.item;
|
||||||
@ -80,7 +80,7 @@ fn every(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.to_output_stream())
|
.to_action_stream())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -31,7 +31,7 @@ impl WholeStreamCommand for Exec {
|
|||||||
"Execute command."
|
"Execute command."
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
|
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||||
exec(args)
|
exec(args)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,7 +52,7 @@ impl WholeStreamCommand for Exec {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
fn exec(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
fn exec(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||||
use std::os::unix::process::CommandExt;
|
use std::os::unix::process::CommandExt;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
@ -74,7 +74,7 @@ fn exec(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(unix))]
|
#[cfg(not(unix))]
|
||||||
fn exec(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
fn exec(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||||
Err(ShellError::labeled_error(
|
Err(ShellError::labeled_error(
|
||||||
"Error on exec",
|
"Error on exec",
|
||||||
"exec is not supported on your platform",
|
"exec is not supported on your platform",
|
||||||
|
@ -23,7 +23,7 @@ impl WholeStreamCommand for Exit {
|
|||||||
"Exit the current shell (or all shells)."
|
"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)
|
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 args = args.evaluate_once()?;
|
||||||
|
|
||||||
let code = if let Some(value) = args.call_info.args.nth(0) {
|
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)
|
CommandAction::LeaveShell(code)
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(OutputStream::one(ReturnSuccess::action(command_action)))
|
Ok(ActionStream::one(ReturnSuccess::action(command_action)))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -28,7 +28,7 @@ impl WholeStreamCommand for First {
|
|||||||
"Show only the first number of rows."
|
"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)
|
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 (FirstArgs { rows }, input) = args.process()?;
|
||||||
let rows_desired = if let Some(quantity) = rows {
|
let rows_desired = if let Some(quantity) = rows {
|
||||||
*quantity
|
*quantity
|
||||||
@ -59,7 +59,7 @@ fn first(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
1
|
1
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(input.take(rows_desired).to_output_stream())
|
Ok(input.take(rows_desired).to_action_stream())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -26,7 +26,7 @@ impl WholeStreamCommand for Command {
|
|||||||
"Flatten the table."
|
"Flatten the table."
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
|
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||||
flatten(args)
|
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 tag = args.call_info.name_tag.clone();
|
||||||
let (Arguments { rest: columns }, input) = args.process()?;
|
let (Arguments { rest: columns }, input) = args.process()?;
|
||||||
|
|
||||||
Ok(input
|
Ok(input
|
||||||
.map(move |item| flat_value(&columns, &item, &tag).into_iter())
|
.map(move |item| flat_value(&columns, &item, &tag).into_iter())
|
||||||
.flatten()
|
.flatten()
|
||||||
.to_output_stream())
|
.to_action_stream())
|
||||||
}
|
}
|
||||||
|
|
||||||
enum TableInside<'a> {
|
enum TableInside<'a> {
|
||||||
|
@ -30,7 +30,7 @@ impl WholeStreamCommand for Format {
|
|||||||
"Format columns into a string using a simple pattern."
|
"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)
|
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 ctx = Arc::new(EvaluationContext::from_args(&args));
|
||||||
let (FormatArgs { pattern }, input) = args.process()?;
|
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())
|
ReturnSuccess::value(UntaggedValue::string(output).into_untagged_value())
|
||||||
})
|
})
|
||||||
.to_output_stream())
|
.to_action_stream())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -39,7 +39,7 @@ impl WholeStreamCommand for FileSize {
|
|||||||
"Converts a column of filesizes to some specified format"
|
"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)
|
filesize(args)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,7 +63,7 @@ fn process_row(
|
|||||||
input: Value,
|
input: Value,
|
||||||
format: Tagged<String>,
|
format: Tagged<String>,
|
||||||
field: Arc<ColumnPath>,
|
field: Arc<ColumnPath>,
|
||||||
) -> Result<OutputStream, ShellError> {
|
) -> Result<ActionStream, ShellError> {
|
||||||
Ok({
|
Ok({
|
||||||
let replace_for = get_data_by_column_path(&input, &field, move |_, _, error| error);
|
let replace_for = get_data_by_column_path(&input, &field, move |_, _, error| error);
|
||||||
match replace_for {
|
match replace_for {
|
||||||
@ -75,7 +75,7 @@ fn process_row(
|
|||||||
{
|
{
|
||||||
let byte_format = InlineShape::format_bytes(&fs, Some(&format.item));
|
let byte_format = InlineShape::format_bytes(&fs, Some(&format.item));
|
||||||
let byte_value = Value::from(byte_format.1);
|
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"),
|
input.replace_data_at_column_path(&field, byte_value).expect("Given that the existence check was already done, this shouldn't trigger never"),
|
||||||
))
|
))
|
||||||
} else {
|
} 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 (Arguments { field, format }, input) = raw_args.process()?;
|
||||||
let field = Arc::new(field);
|
let field = Arc::new(field);
|
||||||
|
|
||||||
@ -102,11 +102,11 @@ fn filesize(raw_args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
|
|
||||||
match process_row(input, format, field) {
|
match process_row(input, format, field) {
|
||||||
Ok(s) => s,
|
Ok(s) => s,
|
||||||
Err(e) => OutputStream::one(Err(e)),
|
Err(e) => ActionStream::one(Err(e)),
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.flatten()
|
.flatten()
|
||||||
.to_output_stream())
|
.to_action_stream())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -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)."
|
"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> {
|
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||||
Ok(OutputStream::one(ReturnSuccess::value(
|
Ok(ActionStream::one(ReturnSuccess::value(
|
||||||
UntaggedValue::string(get_full_help(&From, &args.scope)).into_value(Tag::unknown()),
|
UntaggedValue::string(get_full_help(&From, &args.scope)).into_value(Tag::unknown()),
|
||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ impl WholeStreamCommand for FromCsv {
|
|||||||
"Parse text as .csv and create table."
|
"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)
|
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 name = args.call_info.name_tag.clone();
|
||||||
|
|
||||||
let (
|
let (
|
||||||
|
@ -51,7 +51,7 @@ pub fn from_delimited_data(
|
|||||||
format_name: &'static str,
|
format_name: &'static str,
|
||||||
input: InputStream,
|
input: InputStream,
|
||||||
name: Tag,
|
name: Tag,
|
||||||
) -> Result<OutputStream, ShellError> {
|
) -> Result<ActionStream, ShellError> {
|
||||||
let name_tag = name;
|
let name_tag = name;
|
||||||
let concat_string = input.collect_string(name_tag.clone())?;
|
let concat_string = input.collect_string(name_tag.clone())?;
|
||||||
let sample_lines = concat_string.item.lines().take(3).collect_vec().join("\n");
|
let sample_lines = concat_string.item.lines().take(3).collect_vec().join("\n");
|
||||||
@ -61,8 +61,8 @@ pub fn from_delimited_data(
|
|||||||
Value {
|
Value {
|
||||||
value: UntaggedValue::Table(list),
|
value: UntaggedValue::Table(list),
|
||||||
..
|
..
|
||||||
} => Ok(list.into_iter().to_output_stream()),
|
} => Ok(list.into_iter().to_action_stream()),
|
||||||
x => Ok(OutputStream::one(x)),
|
x => Ok(ActionStream::one(x)),
|
||||||
},
|
},
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
let line_one = match pretty_csv_error(err) {
|
let line_one = match pretty_csv_error(err) {
|
||||||
|
@ -34,7 +34,7 @@ impl WholeStreamCommand for FromEml {
|
|||||||
"Parse text as .eml and create table."
|
"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)
|
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 tag = args.call_info.name_tag.clone();
|
||||||
let (eml_args, input): (FromEmlArgs, _) = args.process()?;
|
let (eml_args, input): (FromEmlArgs, _) = args.process()?;
|
||||||
let value = input.collect_string(tag.clone())?;
|
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));
|
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)]
|
#[cfg(test)]
|
||||||
|
@ -22,12 +22,12 @@ impl WholeStreamCommand for FromIcs {
|
|||||||
"Parse text as .ics and create table."
|
"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)
|
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 args = args.evaluate_once()?;
|
||||||
let tag = args.name_tag();
|
let tag = args.name_tag();
|
||||||
let input = args.input;
|
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 {
|
fn calendar_to_value(calendar: IcalCalendar, tag: Tag) -> Value {
|
||||||
|
@ -19,7 +19,7 @@ impl WholeStreamCommand for FromIni {
|
|||||||
"Parse text as .ini and create table"
|
"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)
|
from_ini(args)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -59,7 +59,7 @@ pub fn from_ini_string_to_value(
|
|||||||
Ok(convert_ini_top_to_nu_value(&v, tag))
|
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 args = args.evaluate_once()?;
|
||||||
let tag = args.name_tag();
|
let tag = args.name_tag();
|
||||||
let input = args.input;
|
let input = args.input;
|
||||||
@ -70,8 +70,8 @@ fn from_ini(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
Value {
|
Value {
|
||||||
value: UntaggedValue::Table(list),
|
value: UntaggedValue::Table(list),
|
||||||
..
|
..
|
||||||
} => Ok(list.into_iter().to_output_stream()),
|
} => Ok(list.into_iter().to_action_stream()),
|
||||||
x => Ok(OutputStream::one(x)),
|
x => Ok(ActionStream::one(x)),
|
||||||
},
|
},
|
||||||
Err(_) => Err(ShellError::labeled_error_with_secondary(
|
Err(_) => Err(ShellError::labeled_error_with_secondary(
|
||||||
"Could not parse as INI",
|
"Could not parse as INI",
|
||||||
|
@ -27,7 +27,7 @@ impl WholeStreamCommand for FromJson {
|
|||||||
"Parse text as .json and create table."
|
"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)
|
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))
|
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 name_tag = args.call_info.name_tag.clone();
|
||||||
|
|
||||||
let (FromJsonArgs { objects }, input) = args.process()?;
|
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 {
|
} else {
|
||||||
match from_json_string_to_value(concat_string.item, name_tag.clone()) {
|
match from_json_string_to_value(concat_string.item, name_tag.clone()) {
|
||||||
Ok(x) => match x {
|
Ok(x) => match x {
|
||||||
@ -110,16 +110,16 @@ fn from_json(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
} => Ok(list
|
} => Ok(list
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(ReturnSuccess::value)
|
.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) => {
|
Err(e) => {
|
||||||
let mut message = "Could not parse as JSON (".to_string();
|
let mut message = "Could not parse as JSON (".to_string();
|
||||||
message.push_str(&e.to_string());
|
message.push_str(&e.to_string());
|
||||||
message.push(')');
|
message.push(')');
|
||||||
|
|
||||||
Ok(OutputStream::one(Err(
|
Ok(ActionStream::one(Err(
|
||||||
ShellError::labeled_error_with_secondary(
|
ShellError::labeled_error_with_secondary(
|
||||||
message,
|
message,
|
||||||
"input cannot be parsed as JSON",
|
"input cannot be parsed as JSON",
|
||||||
|
@ -30,12 +30,12 @@ impl WholeStreamCommand for FromOds {
|
|||||||
"Parse OpenDocument Spreadsheet(.ods) data and create table."
|
"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)
|
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 tag = args.call_info.name_tag.clone();
|
||||||
let span = tag.span;
|
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)]
|
#[cfg(test)]
|
||||||
|
@ -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."
|
"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)
|
from_ssv(args)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -246,7 +246,7 @@ fn from_ssv_string_to_value(
|
|||||||
UntaggedValue::Table(rows).into_value(&tag)
|
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 name = args.call_info.name_tag.clone();
|
||||||
let (
|
let (
|
||||||
FromSsvArgs {
|
FromSsvArgs {
|
||||||
@ -276,8 +276,8 @@ fn from_ssv(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
} => list
|
} => list
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(ReturnSuccess::value)
|
.map(ReturnSuccess::value)
|
||||||
.to_output_stream(),
|
.to_action_stream(),
|
||||||
x => OutputStream::one(ReturnSuccess::value(x)),
|
x => ActionStream::one(ReturnSuccess::value(x)),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ impl WholeStreamCommand for FromToml {
|
|||||||
"Parse text as .toml and create table."
|
"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)
|
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))
|
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 args = args.evaluate_once()?;
|
||||||
let tag = args.name_tag();
|
let tag = args.name_tag();
|
||||||
let input = args.input;
|
let input = args.input;
|
||||||
@ -75,8 +75,8 @@ pub fn from_toml(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
} => list
|
} => list
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(ReturnSuccess::value)
|
.map(ReturnSuccess::value)
|
||||||
.to_output_stream(),
|
.to_action_stream(),
|
||||||
x => OutputStream::one(ReturnSuccess::value(x)),
|
x => ActionStream::one(ReturnSuccess::value(x)),
|
||||||
},
|
},
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
return Err(ShellError::labeled_error_with_secondary(
|
return Err(ShellError::labeled_error_with_secondary(
|
||||||
|
@ -28,12 +28,12 @@ impl WholeStreamCommand for FromTsv {
|
|||||||
"Parse text as .tsv and create table."
|
"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)
|
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 name = args.call_info.name_tag.clone();
|
||||||
let (FromTsvArgs { noheaders }, input) = args.process()?;
|
let (FromTsvArgs { noheaders }, input) = args.process()?;
|
||||||
|
|
||||||
|
@ -18,12 +18,12 @@ impl WholeStreamCommand for FromUrl {
|
|||||||
"Parse url-encoded string as a table."
|
"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)
|
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 args = args.evaluate_once()?;
|
||||||
let tag = args.name_tag();
|
let tag = args.name_tag();
|
||||||
let input = args.input;
|
let input = args.input;
|
||||||
@ -40,7 +40,7 @@ fn from_url(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
row.insert_untagged(k, UntaggedValue::string(v));
|
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(
|
_ => Err(ShellError::labeled_error_with_secondary(
|
||||||
"String not compatible with url-encoding",
|
"String not compatible with url-encoding",
|
||||||
|
@ -21,12 +21,12 @@ impl WholeStreamCommand for FromVcf {
|
|||||||
"Parse text as .vcf and create table."
|
"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)
|
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 args = args.evaluate_once()?;
|
||||||
let tag = args.name_tag();
|
let tag = args.name_tag();
|
||||||
let input = args.input;
|
let input = args.input;
|
||||||
@ -47,7 +47,7 @@ fn from_vcf(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
|
|
||||||
let collected: Vec<_> = iter.collect();
|
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 {
|
fn contact_to_value(contact: VcardContact, tag: Tag) -> Value {
|
||||||
|
@ -30,12 +30,12 @@ impl WholeStreamCommand for FromXlsx {
|
|||||||
"Parse binary Excel(.xlsx) data and create table."
|
"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)
|
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 tag = args.call_info.name_tag.clone();
|
||||||
let span = tag.span;
|
let span = tag.span;
|
||||||
let (
|
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)]
|
#[cfg(test)]
|
||||||
|
@ -18,7 +18,7 @@ impl WholeStreamCommand for FromXml {
|
|||||||
"Parse text as .xml and create table."
|
"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)
|
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))
|
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 args = args.evaluate_once()?;
|
||||||
let tag = args.name_tag();
|
let tag = args.name_tag();
|
||||||
let input = args.input;
|
let input = args.input;
|
||||||
@ -110,8 +110,8 @@ fn from_xml(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
} => list
|
} => list
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(ReturnSuccess::value)
|
.map(ReturnSuccess::value)
|
||||||
.to_output_stream(),
|
.to_action_stream(),
|
||||||
x => OutputStream::one(ReturnSuccess::value(x)),
|
x => ActionStream::one(ReturnSuccess::value(x)),
|
||||||
},
|
},
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
return Err(ShellError::labeled_error_with_secondary(
|
return Err(ShellError::labeled_error_with_secondary(
|
||||||
|
@ -18,7 +18,7 @@ impl WholeStreamCommand for FromYaml {
|
|||||||
"Parse text as .yaml/.yml and create table."
|
"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)
|
from_yaml(args)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -38,7 +38,7 @@ impl WholeStreamCommand for FromYml {
|
|||||||
"Parse text as .yaml/.yml and create table."
|
"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)
|
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)
|
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 args = args.evaluate_once()?;
|
||||||
let tag = args.name_tag();
|
let tag = args.name_tag();
|
||||||
let input = args.input;
|
let input = args.input;
|
||||||
@ -143,8 +143,8 @@ fn from_yaml(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
Value {
|
Value {
|
||||||
value: UntaggedValue::Table(list),
|
value: UntaggedValue::Table(list),
|
||||||
..
|
..
|
||||||
} => Ok(list.into_iter().to_output_stream()),
|
} => Ok(list.into_iter().to_action_stream()),
|
||||||
x => Ok(OutputStream::one(x)),
|
x => Ok(ActionStream::one(x)),
|
||||||
},
|
},
|
||||||
Err(_) => Err(ShellError::labeled_error_with_secondary(
|
Err(_) => Err(ShellError::labeled_error_with_secondary(
|
||||||
"Could not parse as YAML",
|
"Could not parse as YAML",
|
||||||
|
@ -34,7 +34,7 @@ impl WholeStreamCommand for Command {
|
|||||||
"Open given cells as text."
|
"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)
|
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 (Arguments { mut rest }, mut input) = args.process()?;
|
||||||
let (column_paths, _) = arguments(&mut rest)?;
|
let (column_paths, _) = arguments(&mut rest)?;
|
||||||
|
|
||||||
@ -66,7 +66,7 @@ pub fn get(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
Ok(descs
|
Ok(descs
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(ReturnSuccess::value)
|
.map(ReturnSuccess::value)
|
||||||
.to_output_stream())
|
.to_action_stream())
|
||||||
} else {
|
} else {
|
||||||
trace!("get {:?}", column_paths);
|
trace!("get {:?}", column_paths);
|
||||||
let output_stream = input
|
let output_stream = input
|
||||||
@ -78,7 +78,7 @@ pub fn get(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
})
|
})
|
||||||
.flatten()
|
.flatten()
|
||||||
.to_output_stream();
|
.to_action_stream();
|
||||||
Ok(output_stream)
|
Ok(output_stream)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ use crate::prelude::*;
|
|||||||
use crate::utils::suggestions::suggestions;
|
use crate::utils::suggestions::suggestions;
|
||||||
use nu_engine::WholeStreamCommand;
|
use nu_engine::WholeStreamCommand;
|
||||||
use nu_errors::ShellError;
|
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_source::Tagged;
|
||||||
use nu_value_ext::as_string;
|
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()) {
|
match crate::commands::each::process_row(run, context, value.clone()) {
|
||||||
Ok(mut s) => {
|
Ok(mut s) => {
|
||||||
let collection: Vec<Result<ReturnSuccess, ShellError>> = s.drain_vec();
|
let collection: Vec<Value> = s.drain_vec();
|
||||||
|
|
||||||
if collection.len() > 1 {
|
if collection.len() > 1 {
|
||||||
return Err(ShellError::labeled_error(
|
return Err(ShellError::labeled_error(
|
||||||
@ -161,14 +161,12 @@ pub fn group_by(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let value = match collection.get(0) {
|
let value = match collection.get(0) {
|
||||||
Some(Ok(return_value)) => {
|
Some(Value {
|
||||||
return_value.raw_value().unwrap_or_else(|| {
|
value: UntaggedValue::Error(_),
|
||||||
UntaggedValue::string(error_key).into_value(&name)
|
..
|
||||||
})
|
})
|
||||||
}
|
| None => UntaggedValue::string(error_key).into_value(&name),
|
||||||
Some(Err(_)) | None => {
|
Some(return_value) => return_value.clone(),
|
||||||
UntaggedValue::string(error_key).into_value(&name)
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
keys.push(as_string(&value));
|
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),
|
Grouper::ByColumn(column_name) => group(&column_name, &values, &name),
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(OutputStream::one(ReturnSuccess::value(group_value?)))
|
Ok(OutputStream::one(group_value?))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn group(
|
pub fn group(
|
||||||
|
@ -37,7 +37,7 @@ impl WholeStreamCommand for GroupByDate {
|
|||||||
"creates a table grouped by date."
|
"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)
|
group_by_date(args)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,7 +58,7 @@ enum GroupByColumn {
|
|||||||
Name(Option<Tagged<String>>),
|
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 name = args.call_info.name_tag.clone();
|
||||||
let (
|
let (
|
||||||
GroupByDateArgs {
|
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?)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ impl WholeStreamCommand for SubCommand {
|
|||||||
"base64 encode or decode a value"
|
"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)
|
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 name_tag = args.call_info.name_tag.clone();
|
||||||
|
|
||||||
let (
|
let (
|
||||||
@ -109,7 +109,7 @@ fn operate(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
) = args.process()?;
|
) = args.process()?;
|
||||||
|
|
||||||
if encode.item && decode.item {
|
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",
|
"only one of --decode and --encode flags can be used",
|
||||||
"conflicting flags",
|
"conflicting flags",
|
||||||
name_tag,
|
name_tag,
|
||||||
@ -154,7 +154,7 @@ fn operate(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
ReturnSuccess::value(ret)
|
ReturnSuccess::value(ret)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.to_output_stream())
|
.to_action_stream())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn action(
|
fn action(
|
||||||
|
@ -21,8 +21,8 @@ impl WholeStreamCommand for Command {
|
|||||||
"Apply hash function."
|
"Apply hash function."
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
|
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||||
Ok(OutputStream::one(ReturnSuccess::value(
|
Ok(ActionStream::one(ReturnSuccess::value(
|
||||||
UntaggedValue::string(get_full_help(&Command, &args.scope)).into_value(Tag::unknown()),
|
UntaggedValue::string(get_full_help(&Command, &args.scope)).into_value(Tag::unknown()),
|
||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ impl WholeStreamCommand for SubCommand {
|
|||||||
"md5 encode a value"
|
"md5 encode a value"
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
|
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||||
operate(args)
|
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 (Arguments { rest }, input) = args.process()?;
|
||||||
|
|
||||||
let column_paths: Vec<_> = rest;
|
let column_paths: Vec<_> = rest;
|
||||||
@ -78,7 +78,7 @@ fn operate(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
ReturnSuccess::value(ret)
|
ReturnSuccess::value(ret)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.to_output_stream())
|
.to_action_stream())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn action(input: &Value, tag: impl Into<Tag>) -> Result<Value, ShellError> {
|
fn action(input: &Value, tag: impl Into<Tag>) -> Result<Value, ShellError> {
|
||||||
|
@ -21,7 +21,7 @@ impl WholeStreamCommand for Headers {
|
|||||||
"Use the first row of the table as column names."
|
"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)
|
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 input = args.input;
|
||||||
let rows: Vec<Value> = input.collect();
|
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)]
|
#[cfg(test)]
|
||||||
|
@ -31,12 +31,12 @@ impl WholeStreamCommand for Help {
|
|||||||
"Display help information about commands."
|
"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)
|
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 name = args.call_info.name_tag.clone();
|
||||||
let scope = args.scope.clone();
|
let scope = args.scope.clone();
|
||||||
let (HelpArgs { rest }, ..) = args.process()?;
|
let (HelpArgs { rest }, ..) = args.process()?;
|
||||||
@ -154,24 +154,24 @@ fn help(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
ReturnSuccess::value(short_desc.into_value())
|
ReturnSuccess::value(short_desc.into_value())
|
||||||
});
|
});
|
||||||
|
|
||||||
Ok(iterator.to_output_stream())
|
Ok(iterator.to_action_stream())
|
||||||
} else if rest[0].item == "generate_docs" {
|
} else if rest[0].item == "generate_docs" {
|
||||||
Ok(OutputStream::one(ReturnSuccess::value(generate_docs(
|
Ok(ActionStream::one(ReturnSuccess::value(generate_docs(
|
||||||
&scope,
|
&scope,
|
||||||
))))
|
))))
|
||||||
} else if rest.len() == 2 {
|
} else if rest.len() == 2 {
|
||||||
// Check for a subcommand
|
// Check for a subcommand
|
||||||
let command_name = format!("{} {}", rest[0].item, rest[1].item);
|
let command_name = format!("{} {}", rest[0].item, rest[1].item);
|
||||||
if let Some(command) = scope.get_command(&command_name) {
|
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))
|
UntaggedValue::string(get_full_help(command.stream_command(), &scope))
|
||||||
.into_value(Tag::unknown()),
|
.into_value(Tag::unknown()),
|
||||||
)))
|
)))
|
||||||
} else {
|
} else {
|
||||||
Ok(OutputStream::empty())
|
Ok(ActionStream::empty())
|
||||||
}
|
}
|
||||||
} else if let Some(command) = scope.get_command(&rest[0].item) {
|
} 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))
|
UntaggedValue::string(get_full_help(command.stream_command(), &scope))
|
||||||
.into_value(Tag::unknown()),
|
.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/"#;
|
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()),
|
UntaggedValue::string(msg).into_value(Tag::unknown()),
|
||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ impl WholeStreamCommand for Histogram {
|
|||||||
"Creates a new table with a histogram based on the column name passed in."
|
"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)
|
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 name = args.call_info.name_tag.clone();
|
||||||
let (input, args) = args.evaluate_once()?.parts();
|
let (input, args) = args.evaluate_once()?.parts();
|
||||||
|
|
||||||
@ -177,7 +177,7 @@ pub fn histogram(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
|
|
||||||
ReturnSuccess::value(fact.into_value())
|
ReturnSuccess::value(fact.into_value())
|
||||||
})
|
})
|
||||||
.to_output_stream())
|
.to_action_stream())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn evaluator(by: ColumnPath) -> Box<dyn Fn(usize, &Value) -> Result<Value, ShellError> + Send> {
|
fn evaluator(by: ColumnPath) -> Box<dyn Fn(usize, &Value) -> Result<Value, ShellError> + Send> {
|
||||||
|
@ -25,12 +25,12 @@ impl WholeStreamCommand for History {
|
|||||||
"Display command history."
|
"Display command history."
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
|
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||||
history(args)
|
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 tag = args.call_info.name_tag.clone();
|
||||||
let ctx = EvaluationContext::from_args(&args);
|
let ctx = EvaluationContext::from_args(&args);
|
||||||
let (Arguments { clear }, _) = args.process()?;
|
let (Arguments { clear }, _) = args.process()?;
|
||||||
@ -44,7 +44,7 @@ fn history(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
match clear {
|
match clear {
|
||||||
Some(_) => {
|
Some(_) => {
|
||||||
// This is a NOOP, the logic to clear is handled in cli.rs
|
// This is a NOOP, the logic to clear is handled in cli.rs
|
||||||
Ok(OutputStream::empty())
|
Ok(ActionStream::empty())
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
if let Ok(file) = File::open(path) {
|
if let Ok(file) = File::open(path) {
|
||||||
@ -57,7 +57,7 @@ fn history(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
Err(_) => None,
|
Err(_) => None,
|
||||||
});
|
});
|
||||||
|
|
||||||
Ok(output.to_output_stream())
|
Ok(output.to_action_stream())
|
||||||
} else {
|
} else {
|
||||||
Err(ShellError::labeled_error(
|
Err(ShellError::labeled_error(
|
||||||
"Could not open history",
|
"Could not open history",
|
||||||
|
@ -6,6 +6,7 @@ use nu_errors::ShellError;
|
|||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
hir::CapturedBlock, hir::ClassifiedCommand, Signature, SyntaxShape, UntaggedValue,
|
hir::CapturedBlock, hir::ClassifiedCommand, Signature, SyntaxShape, UntaggedValue,
|
||||||
};
|
};
|
||||||
|
use nu_stream::OutputStream;
|
||||||
|
|
||||||
pub struct If;
|
pub struct If;
|
||||||
|
|
||||||
@ -110,11 +111,15 @@ fn if_command(raw_args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
};
|
};
|
||||||
context.scope.exit_scope();
|
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(),
|
||||||
|
)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ impl WholeStreamCommand for Command {
|
|||||||
"Insert a new column with a given value."
|
"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)
|
insert(args)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,7 +66,7 @@ fn process_row(
|
|||||||
input: Value,
|
input: Value,
|
||||||
mut value: Arc<Value>,
|
mut value: Arc<Value>,
|
||||||
field: Arc<ColumnPath>,
|
field: Arc<ColumnPath>,
|
||||||
) -> Result<OutputStream, ShellError> {
|
) -> Result<ActionStream, ShellError> {
|
||||||
let value = Arc::make_mut(&mut value);
|
let value = Arc::make_mut(&mut value);
|
||||||
|
|
||||||
Ok(match value {
|
Ok(match value {
|
||||||
@ -116,17 +116,17 @@ fn process_row(
|
|||||||
value: UntaggedValue::Row(_),
|
value: UntaggedValue::Row(_),
|
||||||
..
|
..
|
||||||
} => match obj.insert_data_at_column_path(&field, result) {
|
} => match obj.insert_data_at_column_path(&field, result) {
|
||||||
Ok(v) => OutputStream::one(ReturnSuccess::value(v)),
|
Ok(v) => ActionStream::one(ReturnSuccess::value(v)),
|
||||||
Err(e) => OutputStream::one(Err(e)),
|
Err(e) => ActionStream::one(Err(e)),
|
||||||
},
|
},
|
||||||
_ => OutputStream::one(Err(ShellError::labeled_error(
|
_ => ActionStream::one(Err(ShellError::labeled_error(
|
||||||
"Unrecognized type in stream",
|
"Unrecognized type in stream",
|
||||||
"original value",
|
"original value",
|
||||||
block_tag.clone(),
|
block_tag.clone(),
|
||||||
))),
|
))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => OutputStream::one(Err(e)),
|
Err(e) => ActionStream::one(Err(e)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
value => match input {
|
value => match input {
|
||||||
@ -139,18 +139,18 @@ fn process_row(
|
|||||||
.unwrap_or_else(|| UntaggedValue::nothing().into_untagged_value())
|
.unwrap_or_else(|| UntaggedValue::nothing().into_untagged_value())
|
||||||
.insert_data_at_column_path(&field, value.clone())
|
.insert_data_at_column_path(&field, value.clone())
|
||||||
{
|
{
|
||||||
Ok(v) => OutputStream::one(ReturnSuccess::value(v)),
|
Ok(v) => ActionStream::one(ReturnSuccess::value(v)),
|
||||||
Err(e) => OutputStream::one(Err(e)),
|
Err(e) => ActionStream::one(Err(e)),
|
||||||
},
|
},
|
||||||
_ => match input.insert_data_at_column_path(&field, value.clone()) {
|
_ => match input.insert_data_at_column_path(&field, value.clone()) {
|
||||||
Ok(v) => OutputStream::one(ReturnSuccess::value(v)),
|
Ok(v) => ActionStream::one(ReturnSuccess::value(v)),
|
||||||
Err(e) => OutputStream::one(Err(e)),
|
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 context = Arc::new(EvaluationContext::from_args(&raw_args));
|
||||||
let (Arguments { column, value }, input) = raw_args.process()?;
|
let (Arguments { column, value }, input) = raw_args.process()?;
|
||||||
let value = Arc::new(value);
|
let value = Arc::new(value);
|
||||||
@ -164,9 +164,9 @@ fn insert(raw_args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
|
|
||||||
match process_row(context, input, value, column) {
|
match process_row(context, input, value, column) {
|
||||||
Ok(s) => s,
|
Ok(s) => s,
|
||||||
Err(e) => OutputStream::one(Err(e)),
|
Err(e) => ActionStream::one(Err(e)),
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.flatten()
|
.flatten()
|
||||||
.to_output_stream())
|
.to_action_stream())
|
||||||
}
|
}
|
||||||
|
@ -18,8 +18,8 @@ impl WholeStreamCommand for Command {
|
|||||||
"Apply into function."
|
"Apply into function."
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
|
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||||
Ok(OutputStream::one(ReturnSuccess::value(
|
Ok(ActionStream::one(ReturnSuccess::value(
|
||||||
UntaggedValue::string(get_full_help(&Command, &args.scope)).into_value(Tag::unknown()),
|
UntaggedValue::string(get_full_help(&Command, &args.scope)).into_value(Tag::unknown()),
|
||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ impl WholeStreamCommand for SubCommand {
|
|||||||
"Convert value to integer"
|
"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)
|
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()?;
|
let (Arguments { rest: column_paths }, input) = args.process()?;
|
||||||
|
|
||||||
Ok(input
|
Ok(input
|
||||||
@ -104,7 +104,7 @@ fn into_int(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
ReturnSuccess::value(ret)
|
ReturnSuccess::value(ret)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.to_output_stream())
|
.to_action_stream())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn action(input: &Value, tag: impl Into<Tag>) -> Result<Value, ShellError> {
|
pub fn action(input: &Value, tag: impl Into<Tag>) -> Result<Value, ShellError> {
|
||||||
|
@ -28,7 +28,7 @@ impl WholeStreamCommand for Command {
|
|||||||
"Keep the number of rows only."
|
"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)
|
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 (Arguments { rows }, input) = args.process()?;
|
||||||
let rows_desired = if let Some(quantity) = rows {
|
let rows_desired = if let Some(quantity) = rows {
|
||||||
*quantity
|
*quantity
|
||||||
@ -61,7 +61,7 @@ fn keep(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
1
|
1
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(input.take(rows_desired).to_output_stream())
|
Ok(input.take(rows_desired).to_action_stream())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -27,7 +27,7 @@ impl WholeStreamCommand for SubCommand {
|
|||||||
"Keeps rows until the condition matches."
|
"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 ctx = Arc::new(EvaluationContext::from_args(&args));
|
||||||
|
|
||||||
let call_info = args.evaluate_once()?;
|
let call_info = args.evaluate_once()?;
|
||||||
@ -93,7 +93,7 @@ impl WholeStreamCommand for SubCommand {
|
|||||||
|
|
||||||
!matches!(result, Ok(ref v) if v.is_true())
|
!matches!(result, Ok(ref v) if v.is_true())
|
||||||
})
|
})
|
||||||
.to_output_stream())
|
.to_action_stream())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ impl WholeStreamCommand for SubCommand {
|
|||||||
"Keeps rows while the condition matches."
|
"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 ctx = Arc::new(EvaluationContext::from_args(&args));
|
||||||
let call_info = args.evaluate_once()?;
|
let call_info = args.evaluate_once()?;
|
||||||
|
|
||||||
@ -92,7 +92,7 @@ impl WholeStreamCommand for SubCommand {
|
|||||||
|
|
||||||
matches!(result, Ok(ref v) if v.is_true())
|
matches!(result, Ok(ref v) if v.is_true())
|
||||||
})
|
})
|
||||||
.to_output_stream())
|
.to_action_stream())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ impl WholeStreamCommand for Kill {
|
|||||||
"Kill a process using the process id."
|
"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)
|
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 (
|
let (
|
||||||
KillArgs {
|
KillArgs {
|
||||||
pid,
|
pid,
|
||||||
@ -136,7 +136,7 @@ fn kill(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
|
|
||||||
cmd.status().expect("failed to execute shell command");
|
cmd.status().expect("failed to execute shell command");
|
||||||
|
|
||||||
Ok(OutputStream::empty())
|
Ok(ActionStream::empty())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -28,7 +28,7 @@ impl WholeStreamCommand for Last {
|
|||||||
"Show only the last number of rows."
|
"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)
|
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 (LastArgs { rows }, input) = args.process()?;
|
||||||
let v: Vec<_> = input.into_vec();
|
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);
|
let iter = v.into_iter().skip(beginning_rows_to_skip);
|
||||||
|
|
||||||
Ok((iter).to_output_stream())
|
Ok((iter).to_action_stream())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -28,7 +28,7 @@ impl WholeStreamCommand for Length {
|
|||||||
"Show the total number of rows or items."
|
"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 tag = args.call_info.name_tag.clone();
|
||||||
let (LengthArgs { column }, input) = args.process()?;
|
let (LengthArgs { column }, input) = args.process()?;
|
||||||
|
|
||||||
@ -38,7 +38,7 @@ impl WholeStreamCommand for Length {
|
|||||||
done: false,
|
done: false,
|
||||||
tag,
|
tag,
|
||||||
}
|
}
|
||||||
.to_output_stream())
|
.to_action_stream())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn examples(&self) -> Vec<Example> {
|
fn examples(&self) -> Vec<Example> {
|
||||||
|
@ -27,7 +27,7 @@ impl WholeStreamCommand for Let {
|
|||||||
"Create a variable and give it a value."
|
"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)
|
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 tag = args.call_info.name_tag.clone();
|
||||||
let ctx = EvaluationContext::from_args(&args);
|
let ctx = EvaluationContext::from_args(&args);
|
||||||
let args = args.evaluate_once()?;
|
let args = args.evaluate_once()?;
|
||||||
@ -94,5 +94,5 @@ pub fn letcmd(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
// variable should be set into.
|
// variable should be set into.
|
||||||
ctx.scope.add_var(name, value);
|
ctx.scope.add_var(name, value);
|
||||||
|
|
||||||
Ok(OutputStream::empty())
|
Ok(ActionStream::empty())
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ impl WholeStreamCommand for LetEnv {
|
|||||||
"Create an environment variable and give it a value."
|
"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)
|
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 tag = args.call_info.name_tag.clone();
|
||||||
let ctx = EvaluationContext::from_args(&args);
|
let ctx = EvaluationContext::from_args(&args);
|
||||||
|
|
||||||
@ -99,5 +99,5 @@ pub fn set_env(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
// variable should be set into.
|
// variable should be set into.
|
||||||
ctx.scope.add_env_var(name, value);
|
ctx.scope.add_env_var(name, value);
|
||||||
|
|
||||||
Ok(OutputStream::empty())
|
Ok(ActionStream::empty())
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ impl WholeStreamCommand for Lines {
|
|||||||
"Split single string into rows, one per line."
|
"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)
|
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 leftover_string = Arc::new(Mutex::new(String::new()));
|
||||||
let args = args.evaluate_once()?;
|
let args = args.evaluate_once()?;
|
||||||
let tag = args.name_tag();
|
let tag = args.name_tag();
|
||||||
@ -113,7 +113,7 @@ fn lines(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.flatten()
|
.flatten()
|
||||||
.to_output_stream())
|
.to_action_stream())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -39,7 +39,7 @@ impl WholeStreamCommand for Ls {
|
|||||||
"View the contents of the current or given path."
|
"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 name = args.call_info.name_tag.clone();
|
||||||
let ctrl_c = args.ctrl_c.clone();
|
let ctrl_c = args.ctrl_c.clone();
|
||||||
let shell_manager = args.shell_manager.clone();
|
let shell_manager = args.shell_manager.clone();
|
||||||
|
@ -33,7 +33,7 @@ macro_rules! command {
|
|||||||
fn command($args: EvaluatedCommandArgs, ( $($param_name),*, ): ( $($param_type),*, )) -> Result<OutputStream, ShellError> {
|
fn command($args: EvaluatedCommandArgs, ( $($param_name),*, ): ( $($param_type),*, )) -> Result<OutputStream, ShellError> {
|
||||||
let output = $body;
|
let output = $body;
|
||||||
|
|
||||||
Ok(output.to_output_stream())
|
Ok(output.to_action_stream())
|
||||||
}
|
}
|
||||||
|
|
||||||
let $args = $args.evaluate_once(registry)?;
|
let $args = $args.evaluate_once(registry)?;
|
||||||
|
@ -18,7 +18,7 @@ impl WholeStreamCommand for SubCommand {
|
|||||||
"Returns absolute values of a list of numbers"
|
"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 {
|
let mapped = args.input.map(move |val| match val.value {
|
||||||
UntaggedValue::Primitive(Primitive::Int(val)) => {
|
UntaggedValue::Primitive(Primitive::Int(val)) => {
|
||||||
UntaggedValue::int(val.magnitude().clone()).into()
|
UntaggedValue::int(val.magnitude().clone()).into()
|
||||||
@ -31,7 +31,7 @@ impl WholeStreamCommand for SubCommand {
|
|||||||
}
|
}
|
||||||
other => abs_default(other),
|
other => abs_default(other),
|
||||||
});
|
});
|
||||||
Ok(OutputStream::from_input(mapped))
|
Ok(ActionStream::from_input(mapped))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn examples(&self) -> Vec<Example> {
|
fn examples(&self) -> Vec<Example> {
|
||||||
|
@ -27,7 +27,7 @@ impl WholeStreamCommand for SubCommand {
|
|||||||
"Finds the average of a list of numbers or tables"
|
"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)
|
run_with_function(args, average)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ impl WholeStreamCommand for SubCommand {
|
|||||||
"Applies the ceil function to a list of numbers"
|
"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;
|
let input = args.input;
|
||||||
|
|
||||||
run_with_numerical_functions_on_stream(input, ceil_big_int, ceil_big_decimal, ceil_default)
|
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
Loading…
Reference in New Issue
Block a user