forked from extern/nushell
Finish removing arg deserialization (#3552)
* WIP remove process * WIP * WIP * Finish removing arg deserialization
This commit is contained in:
@ -3,11 +3,6 @@ use nu_engine::WholeStreamCommand;
|
||||
use nu_errors::ShellError;
|
||||
use nu_protocol::{Signature, SyntaxShape, UntaggedValue, Value};
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct Arguments {
|
||||
value: Value,
|
||||
}
|
||||
|
||||
pub struct Command;
|
||||
|
||||
impl WholeStreamCommand for Command {
|
||||
@ -28,11 +23,12 @@ impl WholeStreamCommand for Command {
|
||||
}
|
||||
|
||||
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let (Arguments { mut value }, mut input) = args.process()?;
|
||||
let mut args = args.evaluate_once()?;
|
||||
let mut value: Value = args.req(0)?;
|
||||
|
||||
let mut prepend = vec![];
|
||||
|
||||
if let Some(first) = input.next() {
|
||||
if let Some(first) = args.input.next() {
|
||||
value.tag = first.tag();
|
||||
prepend.push(first);
|
||||
}
|
||||
@ -50,7 +46,7 @@ impl WholeStreamCommand for Command {
|
||||
|
||||
Ok(prepend
|
||||
.into_iter()
|
||||
.chain(input.into_iter().chain(vec![value]))
|
||||
.chain(args.input.into_iter().chain(vec![value]))
|
||||
.to_output_stream())
|
||||
}
|
||||
|
||||
|
@ -15,12 +15,11 @@ use rand::{
|
||||
distributions::Alphanumeric,
|
||||
prelude::{thread_rng, Rng},
|
||||
};
|
||||
use std::convert::TryInto;
|
||||
use std::time::{Duration, Instant};
|
||||
use std::time::Instant;
|
||||
|
||||
pub struct Benchmark;
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
#[derive(Debug)]
|
||||
struct BenchmarkArgs {
|
||||
block: CapturedBlock,
|
||||
passthrough: Option<CapturedBlock>,
|
||||
@ -113,7 +112,7 @@ fn benchmark(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
{
|
||||
let mut indexmap = IndexMap::with_capacity(1);
|
||||
|
||||
let real_time = into_big_int(end_time - start_time);
|
||||
let real_time = (end_time - start_time).as_nanos() as i64;
|
||||
indexmap.insert("real time".to_string(), real_time);
|
||||
benchmark_output(indexmap, output, cmd_args.passthrough, &tag, &mut context)
|
||||
}
|
||||
@ -143,7 +142,7 @@ fn benchmark(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
}
|
||||
|
||||
fn benchmark_output<T, Output>(
|
||||
indexmap: IndexMap<String, BigInt>,
|
||||
indexmap: IndexMap<String, i64>,
|
||||
block_output: Output,
|
||||
passthrough: Option<CapturedBlock>,
|
||||
tag: T,
|
||||
@ -206,13 +205,6 @@ fn add_implicit_autoview(mut block: Arc<Block>) -> Arc<Block> {
|
||||
block
|
||||
}
|
||||
|
||||
fn into_big_int<T: TryInto<Duration>>(time: T) -> BigInt {
|
||||
time.try_into()
|
||||
.unwrap_or_else(|_| Duration::new(0, 0))
|
||||
.as_nanos()
|
||||
.into()
|
||||
}
|
||||
|
||||
fn generate_random_env_value() -> String {
|
||||
let mut thread_rng = thread_rng();
|
||||
let len = thread_rng.gen_range(1, 16 * 1024);
|
||||
|
@ -27,7 +27,9 @@ impl WholeStreamCommand for Cd {
|
||||
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
let name = args.call_info.name_tag.clone();
|
||||
let shell_manager = args.shell_manager();
|
||||
let (args, _): (CdArgs, _) = args.process()?;
|
||||
let args = args.evaluate_once()?;
|
||||
let args = CdArgs { path: args.opt(0)? };
|
||||
|
||||
shell_manager.cd(args, name)
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::prelude::*;
|
||||
use nu_engine::WholeStreamCommand;
|
||||
use nu_engine::{shell::CopyArgs, WholeStreamCommand};
|
||||
use nu_errors::ShellError;
|
||||
use nu_protocol::{Signature, SyntaxShape};
|
||||
|
||||
@ -28,7 +28,13 @@ impl WholeStreamCommand for Cpy {
|
||||
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
let shell_manager = args.shell_manager();
|
||||
let name = args.call_info.name_tag.clone();
|
||||
let (args, _) = args.process()?;
|
||||
let args = args.evaluate_once()?;
|
||||
|
||||
let args = CopyArgs {
|
||||
src: args.req(0)?,
|
||||
dst: args.req(1)?,
|
||||
recursive: args.has_flag("recursive"),
|
||||
};
|
||||
shell_manager.cp(args, name)
|
||||
}
|
||||
|
||||
|
@ -5,11 +5,6 @@ use nu_protocol::{ReturnSuccess, Signature, UntaggedValue};
|
||||
|
||||
pub struct Debug;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct DebugArgs {
|
||||
raw: bool,
|
||||
}
|
||||
|
||||
impl WholeStreamCommand for Debug {
|
||||
fn name(&self) -> &str {
|
||||
"debug"
|
||||
@ -29,7 +24,10 @@ impl WholeStreamCommand for Debug {
|
||||
}
|
||||
|
||||
fn debug_value(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
let (DebugArgs { raw }, input) = args.process()?;
|
||||
let args = args.evaluate_once()?;
|
||||
let raw = args.has_flag("raw");
|
||||
let input = args.input;
|
||||
|
||||
Ok(input
|
||||
.map(move |v| {
|
||||
if raw {
|
||||
|
@ -5,12 +5,6 @@ use nu_protocol::{ReturnSuccess, Signature, SyntaxShape, UntaggedValue, Value};
|
||||
use nu_source::Tagged;
|
||||
use nu_value_ext::ValueExt;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct DefaultArgs {
|
||||
column: Tagged<String>,
|
||||
value: Value,
|
||||
}
|
||||
|
||||
pub struct Default;
|
||||
|
||||
impl WholeStreamCommand for Default {
|
||||
@ -46,7 +40,11 @@ impl WholeStreamCommand for Default {
|
||||
}
|
||||
|
||||
fn default(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
let (DefaultArgs { column, value }, input) = args.process()?;
|
||||
let args = args.evaluate_once()?;
|
||||
let column: Tagged<String> = args.req(0)?;
|
||||
let value: Value = args.req(1)?;
|
||||
|
||||
let input = args.input;
|
||||
|
||||
Ok(input
|
||||
.map(move |item| {
|
||||
|
@ -88,7 +88,17 @@ fn du(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
let ctrl_c = args.ctrl_c();
|
||||
let ctrl_c_copy = ctrl_c.clone();
|
||||
|
||||
let (args, _): (DuArgs, _) = args.process()?;
|
||||
let args = args.evaluate_once()?;
|
||||
|
||||
let args = DuArgs {
|
||||
path: args.opt(0)?,
|
||||
all: args.has_flag("all"),
|
||||
deref: args.has_flag("deref"),
|
||||
exclude: args.get_flag("exclude")?,
|
||||
max_depth: args.get_flag("max-depth")?,
|
||||
min_size: args.get_flag("min_size")?,
|
||||
};
|
||||
|
||||
let exclude = args.exclude.map_or(Ok(None), move |x| {
|
||||
Pattern::new(&x.item)
|
||||
.map(Option::Some)
|
||||
|
@ -10,11 +10,6 @@ use nu_protocol::{
|
||||
use crate::utils::arguments::arguments;
|
||||
use nu_value_ext::{as_string, ValueExt};
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct Arguments {
|
||||
rest: Vec<Value>,
|
||||
}
|
||||
|
||||
pub struct Command;
|
||||
|
||||
impl WholeStreamCommand for Command {
|
||||
@ -83,9 +78,11 @@ fn is_empty(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
let tag = args.call_info.name_tag.clone();
|
||||
let name_tag = Arc::new(args.call_info.name_tag.clone());
|
||||
let context = Arc::new(EvaluationContext::from_args(&args));
|
||||
let (Arguments { mut rest }, input) = args.process()?;
|
||||
let args = args.evaluate_once()?;
|
||||
let mut rest = args.rest(0)?;
|
||||
let (columns, default_block): (Vec<ColumnPath>, Option<Box<CapturedBlock>>) =
|
||||
arguments(&mut rest)?;
|
||||
let input = args.input;
|
||||
let default_block = Arc::new(default_block);
|
||||
|
||||
if input.is_empty() {
|
||||
|
@ -2,16 +2,9 @@ use crate::prelude::*;
|
||||
use nu_engine::WholeStreamCommand;
|
||||
use nu_errors::ShellError;
|
||||
use nu_protocol::{ReturnSuccess, Signature, SyntaxShape, UntaggedValue};
|
||||
use nu_source::Tagged;
|
||||
|
||||
pub struct Every;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct EveryArgs {
|
||||
stride: Tagged<u64>,
|
||||
skip: Tagged<bool>,
|
||||
}
|
||||
|
||||
impl WholeStreamCommand for Every {
|
||||
fn name(&self) -> &str {
|
||||
"every"
|
||||
@ -63,10 +56,11 @@ impl WholeStreamCommand for Every {
|
||||
}
|
||||
|
||||
fn every(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
let (EveryArgs { stride, skip }, input) = args.process()?;
|
||||
let args = args.evaluate_once()?;
|
||||
|
||||
let stride = stride.item;
|
||||
let skip = skip.item;
|
||||
let stride: u64 = args.req(0)?;
|
||||
let skip: bool = args.has_flag("skip");
|
||||
let input = args.input;
|
||||
|
||||
Ok(input
|
||||
.enumerate()
|
||||
|
@ -57,7 +57,12 @@ fn exec(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
use std::process::Command;
|
||||
|
||||
let name = args.call_info.name_tag.clone();
|
||||
let (args, _): (ExecArgs, _) = args.process()?;
|
||||
let args = args.evaluate_once()?;
|
||||
|
||||
let args = ExecArgs {
|
||||
command: args.req(0)?,
|
||||
rest: args.rest(1)?,
|
||||
};
|
||||
|
||||
let mut command = Command::new(args.command.item);
|
||||
for tagged_arg in args.rest {
|
||||
|
@ -6,11 +6,6 @@ use nu_source::Tagged;
|
||||
|
||||
pub struct First;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct FirstArgs {
|
||||
rows: Option<Tagged<usize>>,
|
||||
}
|
||||
|
||||
impl WholeStreamCommand for First {
|
||||
fn name(&self) -> &str {
|
||||
"first"
|
||||
@ -52,7 +47,10 @@ impl WholeStreamCommand for First {
|
||||
}
|
||||
|
||||
fn first(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
let (FirstArgs { rows }, input) = args.process()?;
|
||||
let args = args.evaluate_once()?;
|
||||
let rows: Option<Tagged<usize>> = args.opt(0)?;
|
||||
let input = args.input;
|
||||
|
||||
let rows_desired = if let Some(quantity) = rows {
|
||||
*quantity
|
||||
} else {
|
||||
|
@ -8,11 +8,6 @@ use nu_source::Tagged;
|
||||
|
||||
pub struct Command;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct Arguments {
|
||||
rest: Vec<Tagged<String>>,
|
||||
}
|
||||
|
||||
impl WholeStreamCommand for Command {
|
||||
fn name(&self) -> &str {
|
||||
"flatten"
|
||||
@ -53,7 +48,9 @@ impl WholeStreamCommand for Command {
|
||||
|
||||
fn flatten(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
let tag = args.call_info.name_tag.clone();
|
||||
let (Arguments { rest: columns }, input) = args.process()?;
|
||||
let args = args.evaluate_once()?;
|
||||
let columns: Vec<Tagged<String>> = args.rest(0)?;
|
||||
let input = args.input;
|
||||
|
||||
Ok(input
|
||||
.map(move |item| flat_value(&columns, &item, &tag).into_iter())
|
||||
|
@ -13,11 +13,6 @@ use nu_value_ext::get_data_by_column_path;
|
||||
|
||||
pub struct Command;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct Arguments {
|
||||
rest: Vec<Value>,
|
||||
}
|
||||
|
||||
impl WholeStreamCommand for Command {
|
||||
fn name(&self) -> &str {
|
||||
"get"
|
||||
@ -55,7 +50,10 @@ impl WholeStreamCommand for Command {
|
||||
}
|
||||
|
||||
pub fn get(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
let (Arguments { mut rest }, mut input) = args.process()?;
|
||||
let args = args.evaluate_once()?;
|
||||
let mut rest: Vec<Value> = args.rest(0)?;
|
||||
let mut input = args.input;
|
||||
|
||||
let (column_paths, _) = arguments(&mut rest)?;
|
||||
|
||||
if column_paths.is_empty() {
|
||||
|
@ -7,12 +7,6 @@ use nu_source::Tagged;
|
||||
|
||||
pub struct GroupByDate;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct GroupByDateArgs {
|
||||
column_name: Option<Tagged<String>>,
|
||||
format: Option<Tagged<String>>,
|
||||
}
|
||||
|
||||
impl WholeStreamCommand for GroupByDate {
|
||||
fn name(&self) -> &str {
|
||||
"group-by date"
|
||||
@ -60,14 +54,11 @@ enum GroupByColumn {
|
||||
|
||||
pub fn group_by_date(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
let name = args.call_info.name_tag.clone();
|
||||
let (
|
||||
GroupByDateArgs {
|
||||
column_name,
|
||||
format,
|
||||
},
|
||||
input,
|
||||
) = args.process()?;
|
||||
let values: Vec<Value> = input.collect();
|
||||
let args = args.evaluate_once()?;
|
||||
let column_name: Option<Tagged<String>> = args.opt(0)?;
|
||||
let format: Option<Tagged<String>> = args.get_flag("format")?;
|
||||
|
||||
let values: Vec<Value> = args.input.collect();
|
||||
|
||||
if values.is_empty() {
|
||||
Err(ShellError::labeled_error(
|
||||
|
@ -13,11 +13,6 @@ use nu_value_ext::ValueExt;
|
||||
|
||||
pub struct Help;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct HelpArgs {
|
||||
rest: Vec<Tagged<String>>,
|
||||
}
|
||||
|
||||
impl WholeStreamCommand for Help {
|
||||
fn name(&self) -> &str {
|
||||
"help"
|
||||
@ -39,7 +34,9 @@ impl WholeStreamCommand for Help {
|
||||
fn help(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
let name = args.call_info.name_tag.clone();
|
||||
let scope = args.scope().clone();
|
||||
let (HelpArgs { rest }, ..) = args.process()?;
|
||||
let args = args.evaluate_once()?;
|
||||
|
||||
let rest: Vec<Tagged<String>> = args.rest(0)?;
|
||||
|
||||
if !rest.is_empty() {
|
||||
if rest[0].item == "commands" {
|
||||
|
@ -5,11 +5,6 @@ use nu_protocol::{ReturnSuccess, Signature, UntaggedValue};
|
||||
use std::fs::File;
|
||||
use std::io::{BufRead, BufReader};
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct Arguments {
|
||||
clear: Option<bool>,
|
||||
}
|
||||
|
||||
pub struct History;
|
||||
|
||||
impl WholeStreamCommand for History {
|
||||
@ -33,7 +28,9 @@ impl WholeStreamCommand for History {
|
||||
fn history(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
let tag = args.call_info.name_tag.clone();
|
||||
let ctx = EvaluationContext::from_args(&args);
|
||||
let (Arguments { clear }, _) = args.process()?;
|
||||
let args = args.evaluate_once()?;
|
||||
|
||||
let clear = args.has_flag("clear");
|
||||
|
||||
let path = if let Some(global_cfg) = &ctx.configs.lock().global_config {
|
||||
nu_data::config::path::history_path_or_default(global_cfg)
|
||||
@ -41,31 +38,26 @@ fn history(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
nu_data::config::path::default_history_path()
|
||||
};
|
||||
|
||||
match clear {
|
||||
Some(_) => {
|
||||
// This is a NOOP, the logic to clear is handled in cli.rs
|
||||
Ok(ActionStream::empty())
|
||||
}
|
||||
None => {
|
||||
if let Ok(file) = File::open(path) {
|
||||
let reader = BufReader::new(file);
|
||||
// Skips the first line, which is a Rustyline internal
|
||||
let output = reader.lines().skip(1).filter_map(move |line| match line {
|
||||
Ok(line) => Some(ReturnSuccess::value(
|
||||
UntaggedValue::string(line).into_value(tag.clone()),
|
||||
)),
|
||||
Err(_) => None,
|
||||
});
|
||||
if clear {
|
||||
// This is a NOOP, the logic to clear is handled in cli.rs
|
||||
Ok(ActionStream::empty())
|
||||
} else if let Ok(file) = File::open(path) {
|
||||
let reader = BufReader::new(file);
|
||||
// Skips the first line, which is a Rustyline internal
|
||||
let output = reader.lines().skip(1).filter_map(move |line| match line {
|
||||
Ok(line) => Some(ReturnSuccess::value(
|
||||
UntaggedValue::string(line).into_value(tag.clone()),
|
||||
)),
|
||||
Err(_) => None,
|
||||
});
|
||||
|
||||
Ok(output.to_action_stream())
|
||||
} else {
|
||||
Err(ShellError::labeled_error(
|
||||
"Could not open history",
|
||||
"history file could not be opened",
|
||||
tag,
|
||||
))
|
||||
}
|
||||
}
|
||||
Ok(output.to_action_stream())
|
||||
} else {
|
||||
Err(ShellError::labeled_error(
|
||||
"Could not open history",
|
||||
"history file could not be opened",
|
||||
tag,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,12 +10,6 @@ use nu_value_ext::ValueExt;
|
||||
|
||||
pub struct Command;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct Arguments {
|
||||
column: ColumnPath,
|
||||
value: Value,
|
||||
}
|
||||
|
||||
impl WholeStreamCommand for Command {
|
||||
fn name(&self) -> &str {
|
||||
"insert"
|
||||
@ -158,9 +152,13 @@ fn process_row(
|
||||
})
|
||||
}
|
||||
|
||||
fn insert(raw_args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
let context = Arc::new(EvaluationContext::from_args(&raw_args));
|
||||
let (Arguments { column, value }, input) = raw_args.process()?;
|
||||
fn insert(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
let context = Arc::new(EvaluationContext::from_args(&args));
|
||||
let args = args.evaluate_once()?;
|
||||
let column: ColumnPath = args.req(0)?;
|
||||
let value: Value = args.req(1)?;
|
||||
let input = args.input;
|
||||
|
||||
let value = Arc::new(value);
|
||||
let column = Arc::new(column);
|
||||
|
||||
|
@ -7,15 +7,6 @@ use std::process::{Command, Stdio};
|
||||
|
||||
pub struct Kill;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct KillArgs {
|
||||
pub pid: Tagged<u64>,
|
||||
pub rest: Vec<Tagged<u64>>,
|
||||
pub force: Tagged<bool>,
|
||||
pub quiet: Tagged<bool>,
|
||||
pub signal: Option<Tagged<u32>>,
|
||||
}
|
||||
|
||||
impl WholeStreamCommand for Kill {
|
||||
fn name(&self) -> &str {
|
||||
"kill"
|
||||
@ -74,20 +65,18 @@ impl WholeStreamCommand for Kill {
|
||||
}
|
||||
|
||||
fn kill(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
let (
|
||||
KillArgs {
|
||||
pid,
|
||||
rest,
|
||||
force,
|
||||
quiet,
|
||||
signal,
|
||||
},
|
||||
..,
|
||||
) = args.process()?;
|
||||
let args = args.evaluate_once()?;
|
||||
|
||||
let pid: Tagged<u64> = args.req(0)?;
|
||||
let rest: Vec<Tagged<u64>> = args.rest(1)?;
|
||||
let force: Option<Tagged<bool>> = args.get_flag("force")?;
|
||||
let quiet: bool = args.has_flag("quiet");
|
||||
let signal: Option<Tagged<u32>> = args.get_flag("signal")?;
|
||||
|
||||
let mut cmd = if cfg!(windows) {
|
||||
let mut cmd = Command::new("taskkill");
|
||||
|
||||
if *force {
|
||||
if matches!(force, Some(Tagged { item: true, .. })) {
|
||||
cmd.arg("/F");
|
||||
}
|
||||
|
||||
@ -105,14 +94,14 @@ fn kill(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
} else {
|
||||
let mut cmd = Command::new("kill");
|
||||
|
||||
if *force {
|
||||
if matches!(force, Some(Tagged { item: true, .. })) {
|
||||
if let Some(signal_value) = signal {
|
||||
return Err(ShellError::labeled_error_with_secondary(
|
||||
"mixing force and signal options is not supported",
|
||||
"signal option",
|
||||
signal_value.tag(),
|
||||
"force option",
|
||||
force.tag(),
|
||||
force.expect("internal error: expected value").tag(),
|
||||
));
|
||||
}
|
||||
cmd.arg("-9");
|
||||
@ -128,7 +117,7 @@ fn kill(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
};
|
||||
|
||||
// pipe everything to null
|
||||
if *quiet {
|
||||
if quiet {
|
||||
cmd.stdin(Stdio::null())
|
||||
.stdout(Stdio::null())
|
||||
.stderr(Stdio::null());
|
||||
|
@ -6,11 +6,6 @@ use nu_protocol::{Signature, UntaggedValue, Value};
|
||||
|
||||
pub struct Length;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct LengthArgs {
|
||||
column: bool,
|
||||
}
|
||||
|
||||
impl WholeStreamCommand for Length {
|
||||
fn name(&self) -> &str {
|
||||
"length"
|
||||
@ -30,7 +25,9 @@ impl WholeStreamCommand for Length {
|
||||
|
||||
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let tag = args.call_info.name_tag.clone();
|
||||
let (LengthArgs { column }, input) = args.process()?;
|
||||
let args = args.evaluate_once()?;
|
||||
let column = args.has_flag("column");
|
||||
let input = args.input;
|
||||
|
||||
Ok(CountIterator {
|
||||
column,
|
||||
|
@ -51,7 +51,10 @@ pub fn set_env(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
let tag = args.call_info.name_tag.clone();
|
||||
let ctx = EvaluationContext::from_args(&args);
|
||||
|
||||
let (LetEnvArgs { name, rhs, .. }, _) = args.process()?;
|
||||
let args = args.evaluate_once()?;
|
||||
|
||||
let name: Tagged<String> = args.req(0)?;
|
||||
let rhs: CapturedBlock = args.req(2)?;
|
||||
|
||||
let (expr, captured) = {
|
||||
if rhs.block.block.len() != 1 {
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::prelude::*;
|
||||
use nu_engine::WholeStreamCommand;
|
||||
use nu_engine::{shell::LsArgs, WholeStreamCommand};
|
||||
use nu_errors::ShellError;
|
||||
use nu_protocol::{Signature, SyntaxShape};
|
||||
|
||||
@ -43,7 +43,16 @@ impl WholeStreamCommand for Ls {
|
||||
let name = args.call_info.name_tag.clone();
|
||||
let ctrl_c = args.ctrl_c();
|
||||
let shell_manager = args.shell_manager();
|
||||
let (args, _) = args.process()?;
|
||||
let args = args.evaluate_once()?;
|
||||
|
||||
let args = LsArgs {
|
||||
path: args.opt(0)?,
|
||||
all: args.has_flag("all"),
|
||||
long: args.has_flag("long"),
|
||||
short_names: args.has_flag("short-names"),
|
||||
du: args.has_flag("du"),
|
||||
};
|
||||
|
||||
shell_manager.ls(args, name, ctrl_c)
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,7 @@ impl WholeStreamCommand for SubCommand {
|
||||
UntaggedValue::decimal(val.abs()).into()
|
||||
}
|
||||
UntaggedValue::Primitive(Primitive::Duration(val)) => {
|
||||
UntaggedValue::duration(val.magnitude().clone()).into()
|
||||
UntaggedValue::duration(val).into()
|
||||
}
|
||||
other => abs_default(other),
|
||||
});
|
||||
|
@ -11,11 +11,6 @@ use nu_protocol::{
|
||||
};
|
||||
pub struct Merge;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct MergeArgs {
|
||||
block: CapturedBlock,
|
||||
}
|
||||
|
||||
impl WholeStreamCommand for Merge {
|
||||
fn name(&self) -> &str {
|
||||
"merge"
|
||||
@ -46,11 +41,13 @@ impl WholeStreamCommand for Merge {
|
||||
}
|
||||
}
|
||||
|
||||
fn merge(raw_args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
let context = EvaluationContext::from_args(&raw_args);
|
||||
let name_tag = raw_args.call_info.name_tag.clone();
|
||||
let (merge_args, input): (MergeArgs, _) = raw_args.process()?;
|
||||
let block = merge_args.block;
|
||||
fn merge(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
let context = EvaluationContext::from_args(&args);
|
||||
let name_tag = args.call_info.name_tag.clone();
|
||||
|
||||
let args = args.evaluate_once()?;
|
||||
let block: CapturedBlock = args.req(0)?;
|
||||
let input = args.input;
|
||||
|
||||
context.scope.enter_scope();
|
||||
context.scope.add_vars(&block.captured.entries);
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::prelude::*;
|
||||
use nu_engine::WholeStreamCommand;
|
||||
use nu_engine::{shell::MkdirArgs, WholeStreamCommand};
|
||||
use nu_errors::ShellError;
|
||||
use nu_protocol::{Signature, SyntaxShape};
|
||||
pub struct Mkdir;
|
||||
@ -38,7 +38,12 @@ impl WholeStreamCommand for Mkdir {
|
||||
fn mkdir(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
let name = args.call_info.name_tag.clone();
|
||||
let shell_manager = args.shell_manager();
|
||||
let (args, _) = args.process()?;
|
||||
|
||||
let args = args.evaluate_once()?;
|
||||
let args = MkdirArgs {
|
||||
rest: args.rest(0)?,
|
||||
show_created_paths: args.has_flag("show-created-paths"),
|
||||
};
|
||||
|
||||
shell_manager.mkdir(args, name)
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::prelude::*;
|
||||
use nu_engine::WholeStreamCommand;
|
||||
use nu_engine::{shell::MvArgs, WholeStreamCommand};
|
||||
use nu_errors::ShellError;
|
||||
use nu_protocol::{Signature, SyntaxShape};
|
||||
|
||||
@ -56,7 +56,12 @@ impl WholeStreamCommand for Mv {
|
||||
fn mv(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
let name = args.call_info.name_tag.clone();
|
||||
let shell_manager = args.shell_manager();
|
||||
let (args, _) = args.process()?;
|
||||
|
||||
let args = args.evaluate_once()?;
|
||||
let args = MvArgs {
|
||||
src: args.req(0)?,
|
||||
dst: args.req(1)?,
|
||||
};
|
||||
|
||||
shell_manager.mv(args, name)
|
||||
}
|
||||
|
@ -4,13 +4,6 @@ use nu_errors::ShellError;
|
||||
use nu_protocol::{Signature, SyntaxShape, Value};
|
||||
use nu_source::Tagged;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct NthArgs {
|
||||
row_number: Tagged<u64>,
|
||||
rest: Vec<Tagged<u64>>,
|
||||
skip: bool,
|
||||
}
|
||||
|
||||
pub struct Nth;
|
||||
|
||||
impl WholeStreamCommand for Nth {
|
||||
@ -59,14 +52,12 @@ impl WholeStreamCommand for Nth {
|
||||
}
|
||||
|
||||
fn nth(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let (
|
||||
NthArgs {
|
||||
row_number,
|
||||
rest: and_rows,
|
||||
skip,
|
||||
},
|
||||
input,
|
||||
) = args.process()?;
|
||||
let args = args.evaluate_once()?;
|
||||
|
||||
let row_number: Tagged<u64> = args.req(0)?;
|
||||
let and_rows: Vec<Tagged<u64>> = args.rest(1)?;
|
||||
let skip = args.has_flag("skip");
|
||||
let input = args.input;
|
||||
|
||||
let mut rows: Vec<_> = and_rows.into_iter().map(|x| x.item as usize).collect();
|
||||
rows.push(row_number.item as usize);
|
||||
|
@ -48,7 +48,10 @@ impl WholeStreamCommand for SubCommand {
|
||||
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
let scope = args.scope().clone();
|
||||
let shell_manager = args.shell_manager();
|
||||
let (Arguments { load_path }, _) = args.process()?;
|
||||
|
||||
let args = args.evaluate_once()?;
|
||||
|
||||
let load_path: Option<Tagged<PathBuf>> = args.get_flag("load")?;
|
||||
|
||||
if let Some(Tagged {
|
||||
item: load_path,
|
||||
|
@ -12,13 +12,6 @@ use std::path::{Path, PathBuf};
|
||||
|
||||
pub struct Open;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct OpenArgs {
|
||||
path: Tagged<PathBuf>,
|
||||
raw: Tagged<bool>,
|
||||
encoding: Option<Tagged<String>>,
|
||||
}
|
||||
|
||||
impl WholeStreamCommand for Open {
|
||||
fn name(&self) -> &str {
|
||||
"open"
|
||||
@ -106,14 +99,10 @@ fn open(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
let name = args.call_info.name_tag.clone();
|
||||
let ctrl_c = args.ctrl_c();
|
||||
|
||||
let (
|
||||
OpenArgs {
|
||||
path,
|
||||
raw,
|
||||
encoding,
|
||||
},
|
||||
_,
|
||||
) = args.process()?;
|
||||
let args = args.evaluate_once()?;
|
||||
let path: Tagged<PathBuf> = args.req(0)?;
|
||||
let raw = args.has_flag("raw");
|
||||
let encoding: Option<Tagged<String>> = args.get_flag("encoding")?;
|
||||
|
||||
if path.is_dir() {
|
||||
let args = nu_engine::shell::LsArgs {
|
||||
@ -132,7 +121,7 @@ fn open(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
// Check if the extension has a "from *" command OR "bat" supports syntax highlighting
|
||||
// AND the user doesn't want the raw output
|
||||
// In these cases, we will collect the Stream
|
||||
let ext = if raw.item {
|
||||
let ext = if raw {
|
||||
None
|
||||
} else {
|
||||
path.extension()
|
||||
|
@ -52,8 +52,15 @@ impl WholeStreamCommand for Pivot {
|
||||
|
||||
pub fn pivot(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
let name = args.call_info.name_tag.clone();
|
||||
let (args, input): (PivotArgs, _) = args.process()?;
|
||||
let input = input.into_vec();
|
||||
//let (args, input): (PivotArgs, _) = args.process()?;
|
||||
let args = args.evaluate_once()?;
|
||||
let pivot_args = PivotArgs {
|
||||
header_row: args.has_flag("header-row"),
|
||||
ignore_titles: args.has_flag("ignore-titles"),
|
||||
rest: args.rest(0)?,
|
||||
};
|
||||
let input = args.input.into_vec();
|
||||
let args = pivot_args;
|
||||
|
||||
let descs = merge_descriptors(&input);
|
||||
|
||||
|
@ -3,11 +3,6 @@ use nu_engine::WholeStreamCommand;
|
||||
use nu_errors::ShellError;
|
||||
use nu_protocol::{Signature, SyntaxShape, UntaggedValue, Value};
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct PrependArgs {
|
||||
row: Value,
|
||||
}
|
||||
|
||||
pub struct Prepend;
|
||||
|
||||
impl WholeStreamCommand for Prepend {
|
||||
@ -46,7 +41,9 @@ impl WholeStreamCommand for Prepend {
|
||||
}
|
||||
|
||||
fn prepend(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let (PrependArgs { row }, input) = args.process()?;
|
||||
let args = args.evaluate_once()?;
|
||||
let row: Value = args.req(0)?;
|
||||
let input = args.input;
|
||||
|
||||
let bos = vec![row].into_iter();
|
||||
|
||||
|
@ -8,7 +8,6 @@ use nu_parser::ParserScope;
|
||||
use nu_protocol::{
|
||||
hir::CapturedBlock, hir::ExternalRedirection, Signature, SyntaxShape, UntaggedValue, Value,
|
||||
};
|
||||
use nu_source::Tagged;
|
||||
use nu_stream::ActionStream;
|
||||
|
||||
pub struct Reduce;
|
||||
@ -17,7 +16,7 @@ pub struct Reduce;
|
||||
pub struct ReduceArgs {
|
||||
block: CapturedBlock,
|
||||
fold: Option<Value>,
|
||||
numbered: Tagged<bool>,
|
||||
numbered: bool,
|
||||
}
|
||||
|
||||
impl WholeStreamCommand for Reduce {
|
||||
@ -107,10 +106,17 @@ fn process_row(
|
||||
result
|
||||
}
|
||||
|
||||
fn reduce(raw_args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
let span = raw_args.call_info.name_tag.span;
|
||||
let context = Arc::new(EvaluationContext::from_args(&raw_args));
|
||||
let (reduce_args, mut input): (ReduceArgs, _) = raw_args.process()?;
|
||||
fn reduce(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
let span = args.call_info.name_tag.span;
|
||||
let context = Arc::new(EvaluationContext::from_args(&args));
|
||||
let args = args.evaluate_once()?;
|
||||
let reduce_args = ReduceArgs {
|
||||
block: args.req(0)?,
|
||||
fold: args.get_flag("fold")?,
|
||||
numbered: args.has_flag("numbered"),
|
||||
};
|
||||
let mut input = args.input;
|
||||
|
||||
let block = Arc::new(reduce_args.block);
|
||||
let (ioffset, start) = if !input.is_empty() {
|
||||
match reduce_args.fold {
|
||||
@ -129,7 +135,7 @@ fn reduce(raw_args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
));
|
||||
};
|
||||
|
||||
if reduce_args.numbered.item {
|
||||
if reduce_args.numbered {
|
||||
// process_row returns Result<InputStream, ShellError>, so we must fold with one
|
||||
let initial = Ok(InputStream::one(each::make_indexed_item(
|
||||
ioffset - 1,
|
||||
|
@ -5,11 +5,6 @@ use nu_errors::ShellError;
|
||||
use nu_protocol::{ReturnSuccess, Signature, SyntaxShape};
|
||||
use nu_source::Tagged;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct RejectArgs {
|
||||
rest: Vec<Tagged<String>>,
|
||||
}
|
||||
|
||||
pub struct Reject;
|
||||
|
||||
impl WholeStreamCommand for Reject {
|
||||
@ -40,7 +35,9 @@ impl WholeStreamCommand for Reject {
|
||||
|
||||
fn reject(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
let name = args.call_info.name_tag.clone();
|
||||
let (RejectArgs { rest: fields }, input) = args.process()?;
|
||||
let args = args.evaluate_once()?;
|
||||
let fields: Vec<Tagged<String>> = args.rest(0)?;
|
||||
|
||||
if fields.is_empty() {
|
||||
return Err(ShellError::labeled_error(
|
||||
"Reject requires fields",
|
||||
@ -51,7 +48,8 @@ fn reject(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
|
||||
let fields: Vec<_> = fields.iter().map(|f| f.item.clone()).collect();
|
||||
|
||||
Ok(input
|
||||
Ok(args
|
||||
.input
|
||||
.map(move |item| ReturnSuccess::value(reject_fields(&item, &fields, &item.tag)))
|
||||
.to_action_stream())
|
||||
}
|
||||
|
@ -7,12 +7,6 @@ use nu_source::Tagged;
|
||||
|
||||
pub struct Rename;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct Arguments {
|
||||
column_name: Tagged<String>,
|
||||
rest: Vec<Tagged<String>>,
|
||||
}
|
||||
|
||||
impl WholeStreamCommand for Rename {
|
||||
fn name(&self) -> &str {
|
||||
"rename"
|
||||
@ -63,7 +57,11 @@ impl WholeStreamCommand for Rename {
|
||||
|
||||
pub fn rename(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
let name = args.call_info.name_tag.clone();
|
||||
let (Arguments { column_name, rest }, input) = args.process()?;
|
||||
let args = args.evaluate_once()?;
|
||||
let column_name: Tagged<String> = args.req(0)?;
|
||||
let rest: Vec<Tagged<String>> = args.rest(1)?;
|
||||
let input = args.input;
|
||||
|
||||
let mut new_column_names = vec![vec![column_name]];
|
||||
new_column_names.push(rest);
|
||||
|
||||
|
@ -65,9 +65,17 @@ impl WholeStreamCommand for Remove {
|
||||
fn rm(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
let name = args.call_info.name_tag.clone();
|
||||
let shell_manager = args.shell_manager();
|
||||
let (args, _): (RemoveArgs, _) = args.process()?;
|
||||
let args = args.evaluate_once()?;
|
||||
|
||||
if args.trash.item && args.permanent.item {
|
||||
let args = RemoveArgs {
|
||||
rest: args.rest(0)?,
|
||||
recursive: args.has_flag("recursive"),
|
||||
trash: args.has_flag("trash"),
|
||||
permanent: args.has_flag("permanent"),
|
||||
force: args.has_flag("force"),
|
||||
};
|
||||
|
||||
if args.trash && args.permanent {
|
||||
return Ok(ActionStream::one(Err(ShellError::labeled_error(
|
||||
"only one of --permanent and --trash can be used",
|
||||
"conflicting flags",
|
||||
|
@ -10,11 +10,6 @@ use nu_value_ext::ValueExt;
|
||||
|
||||
pub struct Command;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct Arguments {
|
||||
rest: Vec<Tagged<String>>,
|
||||
}
|
||||
|
||||
impl WholeStreamCommand for Command {
|
||||
fn name(&self) -> &str {
|
||||
"rotate"
|
||||
@ -38,9 +33,10 @@ impl WholeStreamCommand for Command {
|
||||
|
||||
pub fn rotate(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
let name = args.call_info.name_tag.clone();
|
||||
let (Arguments { rest }, input) = args.process()?;
|
||||
let args = args.evaluate_once()?;
|
||||
let rest: Vec<Tagged<String>> = args.rest(0)?;
|
||||
let input = args.input.into_vec();
|
||||
|
||||
let input = input.into_vec();
|
||||
let total_rows = input.len();
|
||||
let descs = merge_descriptors(&input);
|
||||
let total_descriptors = descs.len();
|
||||
|
@ -10,11 +10,6 @@ use nu_value_ext::ValueExt;
|
||||
|
||||
pub struct SubCommand;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct Arguments {
|
||||
rest: Vec<Tagged<String>>,
|
||||
}
|
||||
|
||||
impl WholeStreamCommand for SubCommand {
|
||||
fn name(&self) -> &str {
|
||||
"rotate counter-clockwise"
|
||||
@ -38,9 +33,10 @@ impl WholeStreamCommand for SubCommand {
|
||||
|
||||
pub fn rotate(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
let name = args.call_info.name_tag.clone();
|
||||
let (Arguments { rest }, input) = args.process()?;
|
||||
let args = args.evaluate_once()?;
|
||||
let rest: Vec<Tagged<String>> = args.rest(0)?;
|
||||
|
||||
let input = input.into_vec();
|
||||
let input = args.input.into_vec();
|
||||
let descs = merge_descriptors(&input);
|
||||
let total_rows = input.len();
|
||||
|
||||
|
@ -8,14 +8,6 @@ use std::cmp;
|
||||
|
||||
pub struct Seq;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct SeqArgs {
|
||||
rest: Vec<Tagged<f64>>,
|
||||
separator: Option<Tagged<String>>,
|
||||
terminator: Option<Tagged<String>>,
|
||||
widths: Tagged<bool>,
|
||||
}
|
||||
|
||||
impl WholeStreamCommand for Seq {
|
||||
fn name(&self) -> &str {
|
||||
"seq"
|
||||
@ -108,15 +100,11 @@ impl WholeStreamCommand for Seq {
|
||||
fn seq(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let name = args.call_info.name_tag.clone();
|
||||
|
||||
let (
|
||||
SeqArgs {
|
||||
rest: rest_nums,
|
||||
separator,
|
||||
terminator,
|
||||
widths,
|
||||
},
|
||||
_,
|
||||
) = args.process()?;
|
||||
let args = args.evaluate_once()?;
|
||||
let rest_nums: Vec<Tagged<f64>> = args.rest(0)?;
|
||||
let separator: Option<Tagged<String>> = args.get_flag("separator")?;
|
||||
let terminator: Option<Tagged<String>> = args.get_flag("terminator")?;
|
||||
let widths = args.has_flag("widths");
|
||||
|
||||
if rest_nums.is_empty() {
|
||||
return Err(ShellError::labeled_error(
|
||||
@ -174,7 +162,7 @@ fn seq(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
|
||||
let rest_nums: Vec<String> = rest_nums.iter().map(|n| n.item.to_string()).collect();
|
||||
|
||||
run_seq(sep, Some(term), widths.item, rest_nums)
|
||||
run_seq(sep, Some(term), widths, rest_nums)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -3,24 +3,12 @@ use chrono::naive::NaiveDate;
|
||||
use chrono::{Duration, Local};
|
||||
use nu_engine::WholeStreamCommand;
|
||||
use nu_errors::ShellError;
|
||||
use nu_protocol::{value::I64Ext, value::StrExt, value::StringExt, value::U64Ext};
|
||||
use nu_protocol::{value::I64Ext, value::StrExt, value::StringExt};
|
||||
use nu_protocol::{ReturnSuccess, Signature, SyntaxShape, UntaggedValue, Value};
|
||||
use nu_source::Tagged;
|
||||
|
||||
pub struct SeqDates;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct SeqDatesArgs {
|
||||
separator: Option<Tagged<String>>,
|
||||
output_format: Option<Tagged<String>>,
|
||||
input_format: Option<Tagged<String>>,
|
||||
begin_date: Option<Tagged<String>>,
|
||||
end_date: Option<Tagged<String>>,
|
||||
increment: Option<Tagged<i64>>,
|
||||
days: Option<Tagged<u64>>,
|
||||
reverse: Tagged<bool>,
|
||||
}
|
||||
|
||||
impl WholeStreamCommand for SeqDates {
|
||||
fn name(&self) -> &str {
|
||||
"seq date"
|
||||
@ -35,24 +23,24 @@ impl WholeStreamCommand for SeqDates {
|
||||
Some('s'),
|
||||
)
|
||||
.named(
|
||||
"output_format",
|
||||
"output-format",
|
||||
SyntaxShape::String,
|
||||
"prints dates in this format (defaults to %Y-%m-%d)",
|
||||
Some('o'),
|
||||
)
|
||||
.named(
|
||||
"input_format",
|
||||
"input-format",
|
||||
SyntaxShape::String,
|
||||
"give argument dates in this format (defaults to %Y-%m-%d)",
|
||||
Some('i'),
|
||||
)
|
||||
.named(
|
||||
"begin_date",
|
||||
"begin-date",
|
||||
SyntaxShape::String,
|
||||
"beginning date range",
|
||||
Some('b'),
|
||||
)
|
||||
.named("end_date", SyntaxShape::String, "ending date", Some('e'))
|
||||
.named("end-date", SyntaxShape::String, "ending date", Some('e'))
|
||||
.named(
|
||||
"increment",
|
||||
SyntaxShape::Int,
|
||||
@ -134,19 +122,16 @@ impl WholeStreamCommand for SeqDates {
|
||||
fn seq_dates(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
let _name = args.call_info.name_tag.clone();
|
||||
|
||||
let (
|
||||
SeqDatesArgs {
|
||||
separator,
|
||||
output_format,
|
||||
input_format,
|
||||
begin_date,
|
||||
end_date,
|
||||
increment,
|
||||
days,
|
||||
reverse,
|
||||
},
|
||||
_,
|
||||
) = args.process()?;
|
||||
let args = args.evaluate_once()?;
|
||||
|
||||
let separator: Option<Tagged<String>> = args.get_flag("separator")?;
|
||||
let output_format: Option<Tagged<String>> = args.get_flag("output-format")?;
|
||||
let input_format: Option<Tagged<String>> = args.get_flag("input-format")?;
|
||||
let begin_date: Option<Tagged<String>> = args.get_flag("begin-date")?;
|
||||
let end_date: Option<Tagged<String>> = args.get_flag("end-date")?;
|
||||
let increment: Option<Tagged<i64>> = args.get_flag("increment")?;
|
||||
let days: Option<Tagged<i64>> = args.get_flag("days")?;
|
||||
let reverse = args.has_flag("reverse");
|
||||
|
||||
let sep: String = match separator {
|
||||
Some(s) => {
|
||||
@ -205,8 +190,8 @@ fn seq_dates(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
};
|
||||
|
||||
let mut rev = false;
|
||||
if *reverse {
|
||||
rev = *reverse;
|
||||
if reverse {
|
||||
rev = reverse;
|
||||
}
|
||||
|
||||
run_seq_dates(sep, outformat, informat, begin, end, inc, day_count, rev)
|
||||
|
@ -6,11 +6,6 @@ use nu_source::Tagged;
|
||||
|
||||
pub struct Command;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct Arguments {
|
||||
rows: Option<Tagged<usize>>,
|
||||
}
|
||||
|
||||
impl WholeStreamCommand for Command {
|
||||
fn name(&self) -> &str {
|
||||
"skip"
|
||||
@ -41,7 +36,10 @@ impl WholeStreamCommand for Command {
|
||||
}
|
||||
|
||||
fn skip(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
let (Arguments { rows }, input) = args.process()?;
|
||||
let args = args.evaluate_once()?;
|
||||
let rows: Option<Tagged<usize>> = args.opt(0)?;
|
||||
let input = args.input;
|
||||
|
||||
let rows_desired = if let Some(quantity) = rows {
|
||||
*quantity
|
||||
} else {
|
||||
|
@ -1,7 +1,7 @@
|
||||
use crate::prelude::*;
|
||||
use nu_engine::WholeStreamCommand;
|
||||
use nu_errors::ShellError;
|
||||
use nu_protocol::{ReturnValue, Signature, SyntaxShape, UntaggedValue};
|
||||
use nu_protocol::{Signature, SyntaxShape, UntaggedValue, Value};
|
||||
use nu_source::Tagged;
|
||||
use std::{
|
||||
sync::atomic::Ordering,
|
||||
@ -13,12 +13,6 @@ const CTRL_C_CHECK_INTERVAL: Duration = Duration::from_millis(100);
|
||||
|
||||
pub struct Sleep;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct SleepArgs {
|
||||
pub duration: Tagged<u64>,
|
||||
pub rest: Vec<Tagged<u64>>,
|
||||
}
|
||||
|
||||
impl WholeStreamCommand for Sleep {
|
||||
fn name(&self) -> &str {
|
||||
"sleep"
|
||||
@ -34,23 +28,28 @@ impl WholeStreamCommand for Sleep {
|
||||
"Delay for a specified amount of time."
|
||||
}
|
||||
|
||||
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let ctrl_c = args.ctrl_c();
|
||||
|
||||
let (SleepArgs { duration, rest }, _) = args.process()?;
|
||||
let args = args.evaluate_once()?;
|
||||
let duration: Tagged<i64> = args.req(0)?;
|
||||
let rest: Vec<Tagged<i64>> = args.rest(1)?;
|
||||
|
||||
let total_dur = Duration::from_nanos(duration.item)
|
||||
+ rest
|
||||
.iter()
|
||||
.map(|val| Duration::from_nanos(val.item))
|
||||
.sum::<Duration>();
|
||||
let total_dur = Duration::from_nanos(if duration.item > 0 {
|
||||
duration.item as u64
|
||||
} else {
|
||||
0
|
||||
}) + rest
|
||||
.iter()
|
||||
.map(|val| Duration::from_nanos(if val.item > 0 { val.item as u64 } else { 0 }))
|
||||
.sum::<Duration>();
|
||||
|
||||
//SleepHandler::new(total_dur, ctrl_c);
|
||||
// this is necessary because the following 2 commands gave different results:
|
||||
// `echo | sleep 1sec` - nothing
|
||||
// `sleep 1sec` - table with 0 elements
|
||||
|
||||
Ok(SleepIterator::new(total_dur, ctrl_c).to_action_stream())
|
||||
Ok(SleepIterator::new(total_dur, ctrl_c).to_output_stream())
|
||||
|
||||
// if input.is_empty() {
|
||||
// Ok(OutputStream::empty())
|
||||
@ -92,7 +91,7 @@ impl SleepIterator {
|
||||
}
|
||||
|
||||
impl Iterator for SleepIterator {
|
||||
type Item = ReturnValue;
|
||||
type Item = Value;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
let start = Instant::now();
|
||||
|
@ -8,13 +8,6 @@ use nu_value_ext::ValueExt;
|
||||
|
||||
pub struct SortBy;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct SortByArgs {
|
||||
rest: Vec<Tagged<String>>,
|
||||
insensitive: bool,
|
||||
reverse: bool,
|
||||
}
|
||||
|
||||
impl WholeStreamCommand for SortBy {
|
||||
fn name(&self) -> &str {
|
||||
"sort-by"
|
||||
@ -35,7 +28,7 @@ impl WholeStreamCommand for SortBy {
|
||||
"Sort by the given columns, in increasing order."
|
||||
}
|
||||
|
||||
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
sort_by(args)
|
||||
}
|
||||
|
||||
@ -111,18 +104,14 @@ impl WholeStreamCommand for SortBy {
|
||||
}
|
||||
}
|
||||
|
||||
fn sort_by(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
fn sort_by(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let tag = args.call_info.name_tag.clone();
|
||||
let mut args = args.evaluate_once()?;
|
||||
|
||||
let (
|
||||
SortByArgs {
|
||||
rest,
|
||||
insensitive,
|
||||
reverse,
|
||||
},
|
||||
mut input,
|
||||
) = args.process()?;
|
||||
let mut vec = input.drain_vec();
|
||||
let rest = args.rest(0)?;
|
||||
let insensitive = args.has_flag("insensitive");
|
||||
let reverse = args.has_flag("reverse");
|
||||
let mut vec = args.input.drain_vec();
|
||||
|
||||
sort(&mut vec, &rest, &tag, insensitive)?;
|
||||
|
||||
@ -130,7 +119,7 @@ fn sort_by(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
vec.reverse()
|
||||
}
|
||||
|
||||
Ok((vec.into_iter()).to_action_stream())
|
||||
Ok((vec.into_iter()).to_output_stream())
|
||||
}
|
||||
|
||||
pub fn sort(
|
||||
|
@ -41,7 +41,8 @@ impl WholeStreamCommand for Source {
|
||||
|
||||
pub fn source(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
let ctx = EvaluationContext::from_args(&args);
|
||||
let (SourceArgs { filename }, _) = args.process()?;
|
||||
let args = args.evaluate_once()?;
|
||||
let filename: Tagged<String> = args.req(0)?;
|
||||
|
||||
// Note: this is a special case for setting the context from a command
|
||||
// In this case, if we don't set it now, we'll lose the scope that this
|
||||
|
@ -7,14 +7,6 @@ use nu_protocol::{
|
||||
};
|
||||
use nu_source::Tagged;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct SplitColumnArgs {
|
||||
separator: Tagged<String>,
|
||||
rest: Vec<Tagged<String>>,
|
||||
#[serde(rename(deserialize = "collapse-empty"))]
|
||||
collapse_empty: bool,
|
||||
}
|
||||
|
||||
pub struct SubCommand;
|
||||
|
||||
impl WholeStreamCommand for SubCommand {
|
||||
@ -26,7 +18,7 @@ impl WholeStreamCommand for SubCommand {
|
||||
Signature::build("split column")
|
||||
.required(
|
||||
"separator",
|
||||
SyntaxShape::Any,
|
||||
SyntaxShape::String,
|
||||
"the character that denotes what separates columns",
|
||||
)
|
||||
.switch("collapse-empty", "remove empty columns", Some('c'))
|
||||
@ -44,14 +36,11 @@ impl WholeStreamCommand for SubCommand {
|
||||
|
||||
fn split_column(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
let name_span = args.call_info.name_tag.span;
|
||||
let (
|
||||
SplitColumnArgs {
|
||||
separator,
|
||||
rest,
|
||||
collapse_empty,
|
||||
},
|
||||
input,
|
||||
) = args.process()?;
|
||||
let args = args.evaluate_once()?;
|
||||
let separator: Tagged<String> = args.req(0)?;
|
||||
let rest: Vec<Tagged<String>> = args.rest(1)?;
|
||||
let collapse_empty = args.has_flag("collapse-empty");
|
||||
let input = args.input;
|
||||
|
||||
Ok(input
|
||||
.map(move |v| {
|
||||
|
@ -5,11 +5,6 @@ use nu_errors::ShellError;
|
||||
use nu_protocol::{Primitive, ReturnSuccess, Signature, SyntaxShape, UntaggedValue};
|
||||
use nu_source::Tagged;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct SplitRowArgs {
|
||||
separator: Tagged<String>,
|
||||
}
|
||||
|
||||
pub struct SubCommand;
|
||||
|
||||
impl WholeStreamCommand for SubCommand {
|
||||
@ -20,7 +15,7 @@ impl WholeStreamCommand for SubCommand {
|
||||
fn signature(&self) -> Signature {
|
||||
Signature::build("split row").required(
|
||||
"separator",
|
||||
SyntaxShape::Any,
|
||||
SyntaxShape::String,
|
||||
"the character that denotes what separates rows",
|
||||
)
|
||||
}
|
||||
@ -36,7 +31,11 @@ impl WholeStreamCommand for SubCommand {
|
||||
|
||||
fn split_row(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
let name = args.call_info.name_tag.clone();
|
||||
let (SplitRowArgs { separator }, input) = args.process()?;
|
||||
let args = args.evaluate_once()?;
|
||||
|
||||
let separator: Tagged<String> = args.req(0)?;
|
||||
let input = args.input;
|
||||
|
||||
Ok(input
|
||||
.flat_map(move |v| {
|
||||
if let Ok(s) = v.as_string() {
|
||||
|
@ -8,11 +8,6 @@ use nu_value_ext::as_string;
|
||||
|
||||
pub struct SplitBy;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct SplitByArgs {
|
||||
column_name: Option<Tagged<String>>,
|
||||
}
|
||||
|
||||
impl WholeStreamCommand for SplitBy {
|
||||
fn name(&self) -> &str {
|
||||
"split-by"
|
||||
@ -37,8 +32,10 @@ impl WholeStreamCommand for SplitBy {
|
||||
|
||||
pub fn split_by(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
let name = args.call_info.name_tag.clone();
|
||||
let (SplitByArgs { column_name }, input) = args.process()?;
|
||||
let values: Vec<Value> = input.collect();
|
||||
let args = args.evaluate_once()?;
|
||||
let column_name: Option<Tagged<String>> = args.opt(0)?;
|
||||
|
||||
let values: Vec<Value> = args.input.collect();
|
||||
|
||||
if values.len() > 1 || values.is_empty() {
|
||||
return Err(ShellError::labeled_error(
|
||||
|
@ -29,7 +29,10 @@ impl WholeStreamCommand for TermSize {
|
||||
|
||||
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
let tag = args.call_info.name_tag.clone();
|
||||
let (TermSizeArgs { wide, tall }, _) = args.process()?;
|
||||
let args = args.evaluate_once()?;
|
||||
|
||||
let wide = args.has_flag("wide");
|
||||
let tall = args.has_flag("tall");
|
||||
|
||||
let size = term_size::dimensions();
|
||||
match size {
|
||||
|
@ -8,12 +8,6 @@ use std::path::PathBuf;
|
||||
|
||||
pub struct Touch;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct TouchArgs {
|
||||
target: Tagged<PathBuf>,
|
||||
rest: Vec<Tagged<PathBuf>>,
|
||||
}
|
||||
|
||||
impl WholeStreamCommand for Touch {
|
||||
fn name(&self) -> &str {
|
||||
"touch"
|
||||
@ -51,7 +45,9 @@ impl WholeStreamCommand for Touch {
|
||||
}
|
||||
|
||||
fn touch(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
let (TouchArgs { target, rest }, _) = args.process()?;
|
||||
let args = args.evaluate_once()?;
|
||||
let target: Tagged<PathBuf> = args.req(0)?;
|
||||
let rest: Vec<Tagged<PathBuf>> = args.rest(1)?;
|
||||
|
||||
for item in vec![target].into_iter().chain(rest.into_iter()) {
|
||||
match OpenOptions::new().write(true).create(true).open(&item) {
|
||||
|
@ -11,12 +11,6 @@ use nu_value_ext::ValueExt;
|
||||
|
||||
pub struct Command;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct Arguments {
|
||||
field: ColumnPath,
|
||||
replacement: Value,
|
||||
}
|
||||
|
||||
impl WholeStreamCommand for Command {
|
||||
fn name(&self) -> &str {
|
||||
"update"
|
||||
@ -178,10 +172,15 @@ fn process_row(
|
||||
})
|
||||
}
|
||||
|
||||
fn update(raw_args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
let name_tag = Arc::new(raw_args.call_info.name_tag.clone());
|
||||
let context = Arc::new(EvaluationContext::from_args(&raw_args));
|
||||
let (Arguments { field, replacement }, input) = raw_args.process()?;
|
||||
fn update(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
let name_tag = Arc::new(args.call_info.name_tag.clone());
|
||||
let context = Arc::new(EvaluationContext::from_args(&args));
|
||||
let args = args.evaluate_once()?;
|
||||
|
||||
let field: ColumnPath = args.req(0)?;
|
||||
let replacement: Value = args.req(1)?;
|
||||
let input = args.input;
|
||||
|
||||
let replacement = Arc::new(replacement);
|
||||
let field = Arc::new(field);
|
||||
|
||||
|
@ -1,10 +1,10 @@
|
||||
use url::Url;
|
||||
|
||||
use super::{operate, DefaultArguments};
|
||||
use super::operate;
|
||||
use crate::prelude::*;
|
||||
use nu_engine::WholeStreamCommand;
|
||||
use nu_errors::ShellError;
|
||||
use nu_protocol::{Signature, SyntaxShape, Value};
|
||||
use nu_protocol::{ColumnPath, Signature, SyntaxShape, Value};
|
||||
|
||||
pub struct UrlHost;
|
||||
|
||||
@ -23,7 +23,10 @@ impl WholeStreamCommand for UrlHost {
|
||||
}
|
||||
|
||||
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
let (DefaultArguments { rest }, input) = args.process()?;
|
||||
let args = args.evaluate_once()?;
|
||||
let rest: Vec<ColumnPath> = args.rest(0)?;
|
||||
let input = args.input;
|
||||
|
||||
Ok(operate(input, rest, &host))
|
||||
}
|
||||
|
||||
|
@ -15,11 +15,6 @@ pub use path::UrlPath;
|
||||
pub use query::UrlQuery;
|
||||
pub use scheme::UrlScheme;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct DefaultArguments {
|
||||
rest: Vec<ColumnPath>,
|
||||
}
|
||||
|
||||
fn handle_value<F>(action: &F, v: &Value) -> Result<Value, ShellError>
|
||||
where
|
||||
F: Fn(&Url) -> &str + Send + 'static,
|
||||
|
@ -1,10 +1,10 @@
|
||||
use url::Url;
|
||||
|
||||
use super::{operate, DefaultArguments};
|
||||
use super::operate;
|
||||
use crate::prelude::*;
|
||||
use nu_engine::WholeStreamCommand;
|
||||
use nu_errors::ShellError;
|
||||
use nu_protocol::{Signature, SyntaxShape, Value};
|
||||
use nu_protocol::{ColumnPath, Signature, SyntaxShape, Value};
|
||||
|
||||
pub struct UrlPath;
|
||||
|
||||
@ -23,7 +23,10 @@ impl WholeStreamCommand for UrlPath {
|
||||
}
|
||||
|
||||
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
let (DefaultArguments { rest }, input) = args.process()?;
|
||||
let args = args.evaluate_once()?;
|
||||
let rest: Vec<ColumnPath> = args.rest(0)?;
|
||||
let input = args.input;
|
||||
|
||||
Ok(operate(input, rest, &Url::path))
|
||||
}
|
||||
|
||||
|
@ -1,10 +1,10 @@
|
||||
use url::Url;
|
||||
|
||||
use super::{operate, DefaultArguments};
|
||||
use super::operate;
|
||||
use crate::prelude::*;
|
||||
use nu_engine::WholeStreamCommand;
|
||||
use nu_errors::ShellError;
|
||||
use nu_protocol::{Signature, SyntaxShape, Value};
|
||||
use nu_protocol::{ColumnPath, Signature, SyntaxShape, Value};
|
||||
|
||||
pub struct UrlQuery;
|
||||
|
||||
@ -23,7 +23,9 @@ impl WholeStreamCommand for UrlQuery {
|
||||
}
|
||||
|
||||
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
let (DefaultArguments { rest }, input) = args.process()?;
|
||||
let args = args.evaluate_once()?;
|
||||
let rest: Vec<ColumnPath> = args.rest(0)?;
|
||||
let input = args.input;
|
||||
Ok(operate(input, rest, &query))
|
||||
}
|
||||
|
||||
|
@ -1,10 +1,10 @@
|
||||
use url::Url;
|
||||
|
||||
use super::{operate, DefaultArguments};
|
||||
use super::operate;
|
||||
use crate::prelude::*;
|
||||
use nu_engine::WholeStreamCommand;
|
||||
use nu_errors::ShellError;
|
||||
use nu_protocol::{Signature, SyntaxShape, Value};
|
||||
use nu_protocol::{ColumnPath, Signature, SyntaxShape, Value};
|
||||
|
||||
pub struct UrlScheme;
|
||||
|
||||
@ -22,8 +22,9 @@ impl WholeStreamCommand for UrlScheme {
|
||||
}
|
||||
|
||||
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
let (DefaultArguments { rest }, input) = args.process()?;
|
||||
Ok(operate(input, rest, &Url::scheme))
|
||||
let args = args.evaluate_once()?;
|
||||
let rest: Vec<ColumnPath> = args.rest(0)?;
|
||||
Ok(operate(args.input, rest, &Url::scheme))
|
||||
}
|
||||
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
|
@ -10,11 +10,6 @@ use nu_protocol::{
|
||||
|
||||
pub struct Command;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct Arguments {
|
||||
block: CapturedBlock,
|
||||
}
|
||||
|
||||
impl WholeStreamCommand for Command {
|
||||
fn name(&self) -> &str {
|
||||
"where"
|
||||
@ -61,10 +56,13 @@ impl WholeStreamCommand for Command {
|
||||
]
|
||||
}
|
||||
}
|
||||
fn where_command(raw_args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let context = Arc::new(EvaluationContext::from_args(&raw_args));
|
||||
let tag = raw_args.call_info.name_tag.clone();
|
||||
let (Arguments { block }, input) = raw_args.process()?;
|
||||
fn where_command(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let context = Arc::new(EvaluationContext::from_args(&args));
|
||||
let tag = args.call_info.name_tag.clone();
|
||||
let args = args.evaluate_once()?;
|
||||
|
||||
let block: CapturedBlock = args.req(0)?;
|
||||
|
||||
let condition = {
|
||||
if block.block.block.len() != 1 {
|
||||
return Err(ShellError::labeled_error(
|
||||
@ -97,7 +95,7 @@ fn where_command(raw_args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
Ok(WhereIterator {
|
||||
condition,
|
||||
context,
|
||||
input,
|
||||
input: args.input,
|
||||
block,
|
||||
}
|
||||
.to_output_stream())
|
||||
|
@ -67,10 +67,12 @@ impl WholeStreamCommand for WithEnv {
|
||||
}
|
||||
}
|
||||
|
||||
fn with_env(raw_args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
let external_redirection = raw_args.call_info.args.external_redirection;
|
||||
let context = EvaluationContext::from_args(&raw_args);
|
||||
let (WithEnvArgs { variable, block }, input) = raw_args.process()?;
|
||||
fn with_env(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
let external_redirection = args.call_info.args.external_redirection;
|
||||
let context = EvaluationContext::from_args(&args);
|
||||
let args = args.evaluate_once()?;
|
||||
let variable: Value = args.req(0)?;
|
||||
let block: CapturedBlock = args.req(1)?;
|
||||
|
||||
let mut env = IndexMap::new();
|
||||
|
||||
@ -108,7 +110,7 @@ fn with_env(raw_args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
context.scope.add_env(env);
|
||||
context.scope.add_vars(&block.captured.entries);
|
||||
|
||||
let result = run_block(&block.block, &context, input, external_redirection);
|
||||
let result = run_block(&block.block, &context, args.input, external_redirection);
|
||||
context.scope.exit_scope();
|
||||
|
||||
result.map(|x| x.to_action_stream())
|
||||
|
@ -9,11 +9,6 @@ const DEFAULT_COLUMN_NAME: &str = "Column";
|
||||
|
||||
pub struct Wrap;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct WrapArgs {
|
||||
column: Option<Tagged<String>>,
|
||||
}
|
||||
|
||||
impl WholeStreamCommand for Wrap {
|
||||
fn name(&self) -> &str {
|
||||
"wrap"
|
||||
@ -78,11 +73,13 @@ impl WholeStreamCommand for Wrap {
|
||||
}
|
||||
|
||||
fn wrap(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
let (WrapArgs { column }, input) = args.process()?;
|
||||
let args = args.evaluate_once()?;
|
||||
let column: Option<Tagged<String>> = args.opt(0)?;
|
||||
|
||||
let mut result_table = vec![];
|
||||
let mut are_all_rows = true;
|
||||
|
||||
for value in input {
|
||||
for value in args.input {
|
||||
match value {
|
||||
Value {
|
||||
value: UntaggedValue::Row(_),
|
||||
|
@ -28,10 +28,11 @@ impl WholeStreamCommand for Command {
|
||||
|
||||
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
let name_tag = args.call_info.name_tag.clone();
|
||||
let (Arguments { rest }, input) = args.process()?;
|
||||
let args = args.evaluate_once()?;
|
||||
let rest: Vec<Value> = args.rest(0)?;
|
||||
|
||||
let mut base_value = UntaggedValue::string("Yehuda Katz in Ecuador").into_value(name_tag);
|
||||
let input: Vec<Value> = input.collect();
|
||||
let input: Vec<Value> = args.input.collect();
|
||||
|
||||
if let Some(first) = input.get(0) {
|
||||
base_value = first.clone()
|
||||
|
@ -3,16 +3,8 @@ use nu_errors::ShellError;
|
||||
use nu_protocol::{ReturnSuccess, Signature, UntaggedValue, Value};
|
||||
use nu_source::{AnchorLocation, Tag};
|
||||
use nu_stream::ActionStream;
|
||||
|
||||
use serde::Deserialize;
|
||||
|
||||
pub struct Command;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct Arguments {
|
||||
path: Option<bool>,
|
||||
}
|
||||
|
||||
impl WholeStreamCommand for Command {
|
||||
fn name(&self) -> &str {
|
||||
"stub open"
|
||||
@ -29,11 +21,11 @@ impl WholeStreamCommand for Command {
|
||||
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
let name_tag = args.call_info.name_tag.clone();
|
||||
|
||||
let (Arguments { path: mocked_path }, _input) = args.process()?;
|
||||
let mocked_path = args.call_info.switch_present("path");
|
||||
|
||||
let out = UntaggedValue::string("Yehuda Katz in Ecuador");
|
||||
|
||||
if let Some(true) = mocked_path {
|
||||
if mocked_path {
|
||||
Ok(ActionStream::one(Ok(ReturnSuccess::Value(Value {
|
||||
value: out,
|
||||
tag: Tag {
|
||||
|
Reference in New Issue
Block a user