Simplify down to one type of context (#3379)

* Simplify down to one type of context

* More simplification
This commit is contained in:
JT
2021-05-03 11:45:55 +12:00
committed by GitHub
parent 4fc05cac56
commit fc59291191
57 changed files with 543 additions and 678 deletions

View File

@ -83,7 +83,7 @@ fn all(args: CommandArgs) -> Result<OutputStream, ShellError> {
}
};
let scope = args.scope.clone();
let scope = args.scope();
let init = Ok(InputStream::one(
UntaggedValue::boolean(true).into_value(&tag),

View File

@ -83,7 +83,7 @@ fn any(args: CommandArgs) -> Result<OutputStream, ShellError> {
}
};
let scope = args.scope.clone();
let scope = args.scope();
let init = Ok(InputStream::one(
UntaggedValue::boolean(false).into_value(&tag),

View File

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

View File

@ -43,14 +43,15 @@ impl WholeStreamCommand for Command {
}
}
pub fn autoview(context: CommandArgs) -> Result<OutputStream, ShellError> {
let configuration = context.configs.lock().global_config();
pub fn autoview(args: CommandArgs) -> Result<OutputStream, ShellError> {
let configuration = args.configs().lock().global_config();
let tag = args.call_info.name_tag.clone();
let binary = context.scope.get_command("binaryview");
let text = context.scope.get_command("textview");
let table = context.scope.get_command("table");
let (mut input_stream, context) = context.split();
let binary = args.scope().get_command("binaryview");
let text = args.scope().get_command("textview");
let table = args.scope().get_command("table");
let context = args.context;
let mut input_stream = args.input;
if let Some(x) = input_stream.next() {
match input_stream.next() {
@ -62,7 +63,7 @@ pub fn autoview(context: CommandArgs) -> Result<OutputStream, ShellError> {
let stream = InputStream::from_stream(xy_stream);
if let Some(table) = table {
let command_args = create_default_command_args(&context).with_input(stream);
let command_args = create_default_command_args(&context, stream, tag);
let result = table.run(command_args)?;
let _ = result.collect::<Vec<_>>();
}
@ -74,12 +75,13 @@ pub fn autoview(context: CommandArgs) -> Result<OutputStream, ShellError> {
tag: Tag { anchor, span },
} if anchor.is_some() => {
if let Some(text) = text {
let mut stream = VecDeque::new();
stream.push_back(
UntaggedValue::string(s).into_value(Tag { anchor, span }),
let command_args = create_default_command_args(
&context,
InputStream::one(
UntaggedValue::string(s).into_value(Tag { anchor, span }),
),
tag,
);
let command_args =
create_default_command_args(&context).with_input(stream);
let result = text.run_with_actions(command_args)?;
let _ = result.collect::<Vec<_>>();
} else {
@ -158,10 +160,8 @@ pub fn autoview(context: CommandArgs) -> Result<OutputStream, ShellError> {
..
} => {
if let Some(binary) = binary {
let mut stream = VecDeque::new();
stream.push_back(x);
let command_args =
create_default_command_args(&context).with_input(stream);
create_default_command_args(&context, InputStream::one(x), tag);
let result = binary.run_with_actions(command_args)?;
let _ = result.collect::<Vec<_>>();
} else {
@ -220,10 +220,8 @@ pub fn autoview(context: CommandArgs) -> Result<OutputStream, ShellError> {
println!("{}", nu_table::draw_table(&table, term_width, &color_hm));
} else if let Some(table) = table {
let mut stream = VecDeque::new();
stream.push_back(x);
let command_args =
create_default_command_args(&context).with_input(stream);
create_default_command_args(&context, InputStream::one(x), tag);
let result = table.run(command_args)?;
let _ = result.collect::<Vec<_>>();
} else {
@ -240,10 +238,8 @@ pub fn autoview(context: CommandArgs) -> Result<OutputStream, ShellError> {
value: ref item, ..
} => {
if let Some(table) = table {
let mut stream = VecDeque::new();
stream.push_back(x);
let command_args =
create_default_command_args(&context).with_input(stream);
create_default_command_args(&context, InputStream::one(x), tag);
let result = table.run(command_args)?;
let _ = result.collect::<Vec<_>>();
} else {
@ -258,14 +254,14 @@ pub fn autoview(context: CommandArgs) -> Result<OutputStream, ShellError> {
Ok(InputStream::empty())
}
fn create_default_command_args(context: &RunnableContextWithoutInput) -> RawCommandArgs {
let span = context.name.span;
RawCommandArgs {
host: context.host.clone(),
ctrl_c: context.ctrl_c.clone(),
configs: context.configs.clone(),
current_errors: context.current_errors.clone(),
shell_manager: context.shell_manager.clone(),
fn create_default_command_args(
context: &EvaluationContext,
input: InputStream,
tag: Tag,
) -> CommandArgs {
let span = tag.span;
CommandArgs {
context: context.clone(),
call_info: UnevaluatedCallInfo {
args: hir::Call {
head: Box::new(SpannedExpression::new(
@ -277,9 +273,9 @@ fn create_default_command_args(context: &RunnableContextWithoutInput) -> RawComm
span,
external_redirection: ExternalRedirection::Stdout,
},
name_tag: context.name.clone(),
name_tag: tag,
},
scope: Scope::new(),
input,
}
}

View File

@ -70,11 +70,11 @@ impl WholeStreamCommand for Benchmark {
}
}
fn benchmark(raw_args: CommandArgs) -> Result<ActionStream, ShellError> {
let tag = raw_args.call_info.args.span;
let mut context = EvaluationContext::from_args(&raw_args);
let scope = raw_args.scope.clone();
let (BenchmarkArgs { block, passthrough }, input) = raw_args.process()?;
fn benchmark(args: CommandArgs) -> Result<ActionStream, ShellError> {
let tag = args.call_info.args.span;
let mut context = EvaluationContext::from_args(&args);
let scope = args.scope().clone();
let (BenchmarkArgs { block, passthrough }, input) = args.process()?;
let env = scope.get_env_vars();
let name = generate_free_name(&env);

View File

@ -1,7 +1,7 @@
use crate::prelude::*;
use chrono::{Datelike, Local, NaiveDate};
use indexmap::IndexMap;
use nu_engine::{EvaluatedWholeStreamCommandArgs, WholeStreamCommand};
use nu_engine::{EvaluatedCommandArgs, WholeStreamCommand};
use nu_errors::ShellError;
use nu_protocol::{Dictionary, Signature, SyntaxShape, UntaggedValue, Value};
@ -165,7 +165,7 @@ fn get_current_date() -> (i32, u32, u32) {
}
fn add_months_of_year_to_table(
args: &EvaluatedWholeStreamCommandArgs,
args: &EvaluatedCommandArgs,
mut calendar_vec_deque: &mut VecDeque<Value>,
tag: &Tag,
selected_year: i32,
@ -198,7 +198,7 @@ fn add_months_of_year_to_table(
}
fn add_month_to_table(
args: &EvaluatedWholeStreamCommandArgs,
args: &EvaluatedCommandArgs,
calendar_vec_deque: &mut VecDeque<Value>,
tag: &Tag,
selected_year: i32,

View File

@ -26,7 +26,7 @@ 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.clone();
let shell_manager = args.shell_manager();
let (args, _): (CdArgs, _) = args.process()?;
shell_manager.cd(args, name)
}

View File

@ -20,14 +20,14 @@ impl WholeStreamCommand for Chart {
}
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(
"nu_plugin_chart not installed.",
));
}
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()),
))))
}
}

View File

@ -534,7 +534,7 @@ mod tests {
use super::{run_external_command, InputStream};
#[cfg(feature = "which")]
use nu_engine::basic_evaluation_context;
use nu_engine::EvaluationContext;
#[cfg(feature = "which")]
use nu_test_support::commands::ExternalBuilder;
@ -557,8 +557,7 @@ mod tests {
let cmd = ExternalBuilder::for_name("i_dont_exist.exe").build();
let input = InputStream::empty();
let mut ctx =
basic_evaluation_context().expect("There was a problem creating a basic context.");
let mut ctx = EvaluationContext::basic();
assert!(run_external_command(cmd, &mut ctx, input, ExternalRedirection::Stdout).is_err());
}
@ -566,7 +565,7 @@ mod tests {
// fn failure_run() -> Result<(), ShellError> {
// let cmd = ExternalBuilder::for_name("fail").build();
// let mut ctx = crate::cli::basic_evaluation_context().expect("There was a problem creating a basic context.");
// let mut ctx = crate::cli::EvaluationContext::basic().expect("There was a problem creating a basic context.");
// let stream = run_external_command(cmd, &mut ctx, None, false)
// ?
// .expect("There was a problem running the external command.");

View File

@ -34,7 +34,7 @@ impl WholeStreamCommand for SubCommand {
pub fn clear(args: CommandArgs) -> Result<ActionStream, ShellError> {
let ctx = EvaluationContext::from_args(&args);
let result = if let Some(global_cfg) = &mut args.configs.lock().global_config {
let result = if let Some(global_cfg) = &mut args.configs().lock().global_config {
global_cfg.vars.clear();
global_cfg.write()?;
ctx.reload_config(global_cfg)?;

View File

@ -21,9 +21,9 @@ impl WholeStreamCommand for Command {
}
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
let name = args.call_info.name_tag;
let name = args.call_info.name_tag.clone();
if let Some(global_cfg) = &args.configs.lock().global_config {
if let Some(global_cfg) = &args.configs().lock().global_config {
let result = global_cfg.vars.clone();
Ok(vec![ReturnSuccess::value(
UntaggedValue::Row(result.into()).into_value(name),

View File

@ -32,7 +32,7 @@ impl WholeStreamCommand for SubCommand {
}
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(ActionStream::one(ReturnSuccess::value(
UntaggedValue::Primitive(Primitive::FilePath(global_cfg.file_path.clone())),
)))

View File

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

View File

@ -20,7 +20,7 @@ impl WholeStreamCommand for Command {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
Ok(ActionStream::one(ReturnSuccess::value(
UntaggedValue::string(get_full_help(&Command, &args.scope)).into_value(Tag::unknown()),
UntaggedValue::string(get_full_help(&Command, args.scope())).into_value(Tag::unknown()),
)))
}
}

View File

@ -1,10 +1,9 @@
use crate::prelude::*;
use nu_engine::basic_evaluation_context;
use nu_engine::whole_stream_command;
use std::error::Error;
pub fn create_default_context(interactive: bool) -> Result<EvaluationContext, Box<dyn Error>> {
let context = basic_evaluation_context()?;
let context = EvaluationContext::basic();
{
use crate::commands::*;

View File

@ -85,7 +85,7 @@ impl WholeStreamCommand for Du {
fn du(args: CommandArgs) -> Result<ActionStream, ShellError> {
let tag = args.call_info.name_tag.clone();
let ctrl_c = args.ctrl_c.clone();
let ctrl_c = args.ctrl_c();
let ctrl_c_copy = ctrl_c.clone();
let (args, _): (DuArgs, _) = args.process()?;

View File

@ -75,16 +75,12 @@ documentation link at https://docs.rs/encoding_rs/0.8.28/encoding_rs/#statics"#
}
}
fn enter(raw_args: CommandArgs) -> Result<ActionStream, ShellError> {
let scope = raw_args.scope.clone();
let shell_manager = raw_args.shell_manager.clone();
let head = raw_args.call_info.args.head.clone();
let ctrl_c = raw_args.ctrl_c.clone();
let configs = raw_args.configs.clone();
let current_errors = raw_args.current_errors.clone();
let host = raw_args.host.clone();
let tag = raw_args.call_info.name_tag.clone();
let (EnterArgs { location, encoding }, _) = raw_args.process()?;
fn enter(args: CommandArgs) -> Result<ActionStream, ShellError> {
let head = args.call_info.args.head.clone();
let context = args.context.clone();
let scope = args.scope().clone();
let path = args.context.shell_manager.path();
let (EnterArgs { location, encoding }, _) = args.process()?;
let location_string = location.display().to_string();
if location.is_dir() {
@ -93,7 +89,7 @@ fn enter(raw_args: CommandArgs) -> Result<ActionStream, ShellError> {
)))
} else {
// If it's a file, attempt to open the file as a value and enter it
let cwd = shell_manager.path();
let cwd = path;
let full_path = std::path::PathBuf::from(cwd);
let span = location.span();
@ -110,12 +106,9 @@ fn enter(raw_args: CommandArgs) -> Result<ActionStream, ShellError> {
if let Some(extension) = file_extension {
let command_name = format!("from {}", extension);
if let Some(converter) = scope.get_command(&command_name) {
let new_args = RawCommandArgs {
host,
ctrl_c,
configs,
current_errors,
shell_manager,
let tag = tagged_contents.tag.clone();
let new_args = CommandArgs {
context,
call_info: UnevaluatedCallInfo {
args: nu_protocol::hir::Call {
head,
@ -124,13 +117,11 @@ fn enter(raw_args: CommandArgs) -> Result<ActionStream, ShellError> {
span: Span::unknown(),
external_redirection: ExternalRedirection::Stdout,
},
name_tag: tag,
name_tag: tag.clone(),
},
scope,
input: InputStream::one(tagged_contents),
};
let tag = tagged_contents.tag.clone();
let mut result =
converter.run(new_args.with_input(vec![tagged_contents]))?;
let mut result = converter.run(new_args)?;
let result_vec: Vec<Value> = result.drain_vec();
Ok(result_vec
.into_iter()

View File

@ -20,7 +20,7 @@ impl WholeStreamCommand for From {
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
Ok(OutputStream::one(
UntaggedValue::string(get_full_help(&From, &args.scope)).into_value(Tag::unknown()),
UntaggedValue::string(get_full_help(&From, args.scope())).into_value(Tag::unknown()),
))
}
}

View File

@ -23,7 +23,7 @@ impl WholeStreamCommand for Command {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
Ok(ActionStream::one(ReturnSuccess::value(
UntaggedValue::string(get_full_help(&Command, &args.scope)).into_value(Tag::unknown()),
UntaggedValue::string(get_full_help(&Command, args.scope())).into_value(Tag::unknown()),
)))
}
}

View File

@ -38,7 +38,7 @@ 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 scope = args.scope().clone();
let (HelpArgs { rest }, ..) = args.process()?;
if !rest.is_empty() {

View File

@ -20,7 +20,7 @@ impl WholeStreamCommand for Command {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
Ok(ActionStream::one(ReturnSuccess::value(
UntaggedValue::string(get_full_help(&Command, &args.scope)).into_value(Tag::unknown()),
UntaggedValue::string(get_full_help(&Command, args.scope())).into_value(Tag::unknown()),
)))
}
}

View File

@ -41,8 +41,8 @@ impl WholeStreamCommand for Ls {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
let name = args.call_info.name_tag.clone();
let ctrl_c = args.ctrl_c.clone();
let shell_manager = args.shell_manager.clone();
let ctrl_c = args.ctrl_c();
let shell_manager = args.shell_manager();
let (args, _) = args.process()?;
shell_manager.ls(args, name, ctrl_c)
}

View File

@ -1,352 +1,351 @@
#[doc(hidden)]
#[macro_export]
macro_rules! command {
(
Named { $export:tt $args:ident $body:block }
Positional { $($number:tt)* }
Rest {}
Signature {
name: $config_name:tt,
mandatory_positional: vec![ $($mandatory_positional:tt)* ],
optional_positional: vec![ $($optional_positional:tt)* ],
rest_positional: $rest_positional:tt,
named: {
$(
($named_param:tt : $named_type:ty : $named_kind:tt)
)*
}
}
// #[doc(hidden)]
// #[macro_export]
// macro_rules! command {
// (
// Named { $export:tt $args:ident $body:block }
// Positional { $($number:tt)* }
// Rest {}
// Signature {
// name: $config_name:tt,
// mandatory_positional: vec![ $($mandatory_positional:tt)* ],
// optional_positional: vec![ $($optional_positional:tt)* ],
// rest_positional: $rest_positional:tt,
// named: {
// $(
// ($named_param:tt : $named_type:ty : $named_kind:tt)
// )*
// }
// }
Function {
$( ( $param_name:tt : $param_type:tt ) )*
}
// Function {
// $( ( $param_name:tt : $param_type:tt ) )*
// }
Extract {
$($extract:tt)*
}
) => {
#[allow(non_camel_case_types)]
pub struct $export;
// Extract {
// $($extract:tt)*
// }
// ) => {
// #[allow(non_camel_case_types)]
// pub struct $export;
impl Command for $export {
fn run(&self, $args: CommandArgs) -> Result<OutputStream, ShellError> {
fn command($args: EvaluatedCommandArgs, ( $($param_name),*, ): ( $($param_type),*, )) -> Result<OutputStream, ShellError> {
let output = $body;
// impl Command for $export {
// fn run(&self, $args: CommandArgs) -> Result<OutputStream, ShellError> {
// fn command($args: EvaluatedCommandArgs, ( $($param_name),*, ): ( $($param_type),*, )) -> Result<OutputStream, ShellError> {
// let output = $body;
Ok(output.to_action_stream())
}
// Ok(output.to_action_stream())
// }
let $args = $args.evaluate_once(registry)?;
let tuple = ( $($extract ,)* );
command( $args, tuple )
}
// let $args = $args.evaluate_once(registry)?;
// let tuple = ( $($extract ,)* );
// command( $args, tuple )
// }
fn name(&self) -> &str {
stringify!($config_name)
}
// fn name(&self) -> &str {
// stringify!($config_name)
// }
fn config(&self) -> $nu_parser::registry::Signature {
$nu_parser::registry::Signature {
name: self.name().to_string(),
positional: vec![$($mandatory_positional)*],
rest_positional: false,
is_filter: false,
is_sink: false,
// fn config(&self) -> $nu_parser::registry::Signature {
// $nu_parser::registry::Signature {
// name: self.name().to_string(),
// positional: vec![$($mandatory_positional)*],
// rest_positional: false,
// is_filter: false,
// is_sink: false,
named: {
use $nu_parser::registry::NamedType;
// named: {
// use $nu_parser::registry::NamedType;
#[allow(unused_mut)]
let mut named: indexmap::IndexMap<String, NamedType> = indexmap::IndexMap::new();
// #[allow(unused_mut)]
// let mut named: indexmap::IndexMap<String, NamedType> = indexmap::IndexMap::new();
$(
named.insert(stringify!($named_param).to_string(), $nu_parser::registry::NamedType::$named_kind);
)*
// $(
// named.insert(stringify!($named_param).to_string(), $nu_parser::registry::NamedType::$named_kind);
// )*
named
}
}
}
}
};
// named
// }
// }
// }
// }
// };
// switch
(
Named { $export:tt $args:ident $body:block }
Positional { $($positional_count:tt)* }
Rest { -- $param_name:ident : Switch , $($rest:tt)* }
Signature {
name: $config_name:tt,
mandatory_positional: vec![ $($mandatory_positional:tt)* ],
optional_positional: vec![ $($optional_positional:tt)* ],
rest_positional: $rest_positional:tt,
named: {
$($config_named:tt)*
}
}
Function {
$($function:tt)*
}
Extract {
$($extract:tt)*
}
) => {
command!(
Named { $export $args $body }
Positional { $($positional_count)* + 1 }
Rest { $($rest)* }
Signature {
name: $config_name,
mandatory_positional: vec![ $($mandatory_positional)* ],
optional_positional: vec![ $($optional_positional)* ],
rest_positional: $rest_positional,
named: {
$($config_named)*
($param_name : Switch : Switch)
}
}
// // switch
// (
// Named { $export:tt $args:ident $body:block }
// Positional { $($positional_count:tt)* }
// Rest { -- $param_name:ident : Switch , $($rest:tt)* }
// Signature {
// name: $config_name:tt,
// mandatory_positional: vec![ $($mandatory_positional:tt)* ],
// optional_positional: vec![ $($optional_positional:tt)* ],
// rest_positional: $rest_positional:tt,
// named: {
// $($config_named:tt)*
// }
// }
// Function {
// $($function:tt)*
// }
// Extract {
// $($extract:tt)*
// }
// ) => {
// command!(
// Named { $export $args $body }
// Positional { $($positional_count)* + 1 }
// Rest { $($rest)* }
// Signature {
// name: $config_name,
// mandatory_positional: vec![ $($mandatory_positional)* ],
// optional_positional: vec![ $($optional_positional)* ],
// rest_positional: $rest_positional,
// named: {
// $($config_named)*
// ($param_name : Switch : Switch)
// }
// }
Function {
$($function)* ($param_name : Switch)
}
// Function {
// $($function)* ($param_name : Switch)
// }
Extract {
$($extract)* {
use std::convert::TryInto;
// Extract {
// $($extract)* {
// use std::convert::TryInto;
$args.get(stringify!($param_name)).try_into()?
}
}
);
};
// $args.get(stringify!($param_name)).try_into()?
// }
// }
// );
// };
// mandatory named arguments
(
Named { $export:tt $args:ident $body:block }
Positional { $($positional_count:tt)* }
Rest { -- $param_name:ident : $param_kind:ty , $($rest:tt)* }
Signature {
name: $config_name:tt,
mandatory_positional: vec![ $($mandatory_positional:tt)* ],
optional_positional: vec![ $($optional_positional:tt)* ],
rest_positional: $rest_positional:tt,
named: {
$($config_named:tt)*
}
}
Function {
$($function:tt)*
}
Extract {
$($extract:tt)*
}
) => {
command!(
Named { $export $args $body }
Positional { $($positional_count)* + 1 }
Rest { $($rest)* }
Signature {
name: $config_name,
mandatory_positional: vec![ $($mandatory_positional)* ],
optional_positional: vec![ $($optional_positional)* ],
rest_positional: $rest_positional,
named: {
$($config_named)*
($param_name : Mandatory(NamedValue::Single))
}
}
// // mandatory named arguments
// (
// Named { $export:tt $args:ident $body:block }
// Positional { $($positional_count:tt)* }
// Rest { -- $param_name:ident : $param_kind:ty , $($rest:tt)* }
// Signature {
// name: $config_name:tt,
// mandatory_positional: vec![ $($mandatory_positional:tt)* ],
// optional_positional: vec![ $($optional_positional:tt)* ],
// rest_positional: $rest_positional:tt,
// named: {
// $($config_named:tt)*
// }
// }
// Function {
// $($function:tt)*
// }
// Extract {
// $($extract:tt)*
// }
// ) => {
// command!(
// Named { $export $args $body }
// Positional { $($positional_count)* + 1 }
// Rest { $($rest)* }
// Signature {
// name: $config_name,
// mandatory_positional: vec![ $($mandatory_positional)* ],
// optional_positional: vec![ $($optional_positional)* ],
// rest_positional: $rest_positional,
// named: {
// $($config_named)*
// ($param_name : Mandatory(NamedValue::Single))
// }
// }
Function {
$($function)* ($param_name : $param_kind)
}
// Function {
// $($function)* ($param_name : $param_kind)
// }
Extract {
$($extract)* {
use std::convert::TryInto;
// Extract {
// $($extract)* {
// use std::convert::TryInto;
$args.get(stringify!($param_name)).try_into()?
}
}
);
};
// $args.get(stringify!($param_name)).try_into()?
// }
// }
// );
// };
// optional named arguments
(
Named { $export:tt $args:ident $body:block }
Positional { $($positional_count:tt)* }
Rest { -- $param_name:ident ? : $param_kind:ty , $($rest:tt)* }
Signature {
name: $config_name:tt,
mandatory_positional: vec![ $($mandatory_positional:tt)* ],
optional_positional: vec![ $($optional_positional:tt)* ],
rest_positional: $rest_positional:tt,
named: {
$($config_named:tt)*
}
}
Function {
$($function:tt)*
}
Extract {
$($extract:tt)*
}
) => {
command!(
Named { $export $args $body }
Positional { $($positional_count)* + 1 }
Rest { $($rest)* }
Signature {
name: $config_name,
mandatory_positional: vec![ $($mandatory_positional)* ],
optional_positional: vec![ $($optional_positional)* ],
rest_positional: $rest_positional,
named: {
$($config_named)*
($param_name : Optional(NamedValue::Single))
}
}
// // optional named arguments
// (
// Named { $export:tt $args:ident $body:block }
// Positional { $($positional_count:tt)* }
// Rest { -- $param_name:ident ? : $param_kind:ty , $($rest:tt)* }
// Signature {
// name: $config_name:tt,
// mandatory_positional: vec![ $($mandatory_positional:tt)* ],
// optional_positional: vec![ $($optional_positional:tt)* ],
// rest_positional: $rest_positional:tt,
// named: {
// $($config_named:tt)*
// }
// }
// Function {
// $($function:tt)*
// }
// Extract {
// $($extract:tt)*
// }
// ) => {
// command!(
// Named { $export $args $body }
// Positional { $($positional_count)* + 1 }
// Rest { $($rest)* }
// Signature {
// name: $config_name,
// mandatory_positional: vec![ $($mandatory_positional)* ],
// optional_positional: vec![ $($optional_positional)* ],
// rest_positional: $rest_positional,
// named: {
// $($config_named)*
// ($param_name : Optional(NamedValue::Single))
// }
// }
Function {
$($function)* ($param_name : $param_kind)
}
// Function {
// $($function)* ($param_name : $param_kind)
// }
Extract {
$($extract)* {
use std::convert::TryInto;
// Extract {
// $($extract)* {
// use std::convert::TryInto;
$args.get(stringify!($param_name)).try_into()?
}
}
);
};
// $args.get(stringify!($param_name)).try_into()?
// }
// }
// );
// };
// mandatory positional block
(
Named { $export:ident $args:ident $body:block }
Positional { $($positional_count:tt)* }
Rest { $param_name:ident : Block , $($rest:tt)* }
Signature {
name: $config_name:tt,
mandatory_positional: vec![ $($mandatory_positional:tt)* ],
optional_positional: vec![ $($optional_positional:tt)* ],
rest_positional: $rest_positional:tt,
named: {
$($config_named:tt)*
}
}
// // mandatory positional block
// (
// Named { $export:ident $args:ident $body:block }
// Positional { $($positional_count:tt)* }
// Rest { $param_name:ident : Block , $($rest:tt)* }
// Signature {
// name: $config_name:tt,
// mandatory_positional: vec![ $($mandatory_positional:tt)* ],
// optional_positional: vec![ $($optional_positional:tt)* ],
// rest_positional: $rest_positional:tt,
// named: {
// $($config_named:tt)*
// }
// }
Function {
$($function:tt)*
}
// Function {
// $($function:tt)*
// }
Extract {
$($extract:tt)*
}
// Extract {
// $($extract:tt)*
// }
) => {
command!(
Named { $export $args $body }
Positional { $($positional_count)* + 1 }
Rest { $($rest)* }
Signature {
name: $config_name,
mandatory_positional: vec![ $($mandatory_positional)* $nu_parser::registry::PositionalType::mandatory_block(
stringify!($param_name)
), ],
optional_positional: vec![ $($optional_positional)* ],
rest_positional: $rest_positional,
named: {
$($config_named)*
}
}
// ) => {
// command!(
// Named { $export $args $body }
// Positional { $($positional_count)* + 1 }
// Rest { $($rest)* }
// Signature {
// name: $config_name,
// mandatory_positional: vec![ $($mandatory_positional)* $nu_parser::registry::PositionalType::mandatory_block(
// stringify!($param_name)
// ), ],
// optional_positional: vec![ $($optional_positional)* ],
// rest_positional: $rest_positional,
// named: {
// $($config_named)*
// }
// }
Function {
$($function)* ($param_name : Block)
}
// Function {
// $($function)* ($param_name : Block)
// }
Extract {
$($extract:tt)* {
use $nu_data::types::ExtractType;
let value = $args.expect_nth($($positional_count)*)?;
Block::extract(value)?
}
}
);
};
// Extract {
// $($extract:tt)* {
// use $nu_data::types::ExtractType;
// let value = $args.expect_nth($($positional_count)*)?;
// Block::extract(value)?
// }
// }
// );
// };
// // mandatory positional argument
// (
// Named { $export:ident $args:ident $body:block }
// Positional { $($positional_count:tt)* }
// Rest { $param_name:ident : $param_kind:ty , $($rest:tt)* }
// Signature {
// name: $config_name:tt,
// mandatory_positional: vec![ $($mandatory_positional:tt)* ],
// optional_positional: vec![ $($optional_positional:tt)* ],
// rest_positional: $rest_positional:tt,
// named: {
// $($config_named:tt)*
// }
// }
// mandatory positional argument
(
Named { $export:ident $args:ident $body:block }
Positional { $($positional_count:tt)* }
Rest { $param_name:ident : $param_kind:ty , $($rest:tt)* }
Signature {
name: $config_name:tt,
mandatory_positional: vec![ $($mandatory_positional:tt)* ],
optional_positional: vec![ $($optional_positional:tt)* ],
rest_positional: $rest_positional:tt,
named: {
$($config_named:tt)*
}
}
// Function {
// $($function:tt)*
// }
Function {
$($function:tt)*
}
// Extract {
// $($extract:tt)*
// }
Extract {
$($extract:tt)*
}
// ) => {
// command!(
// Named { $export $args $body }
// Positional { $($positional_count)* + 1 }
// Rest { $($rest)* }
// Signature {
// name: $config_name,
// mandatory_positional: vec![ $($mandatory_positional)* $nu_parser::registry::PositionalType::mandatory(
// stringify!($param_name), <$param_kind>::syntax_type()
// ), ],
// optional_positional: vec![ $($optional_positional)* ],
// rest_positional: $rest_positional,
// named: {
// $($config_named)*
// }
// }
) => {
command!(
Named { $export $args $body }
Positional { $($positional_count)* + 1 }
Rest { $($rest)* }
Signature {
name: $config_name,
mandatory_positional: vec![ $($mandatory_positional)* $nu_parser::registry::PositionalType::mandatory(
stringify!($param_name), <$param_kind>::syntax_type()
), ],
optional_positional: vec![ $($optional_positional)* ],
rest_positional: $rest_positional,
named: {
$($config_named)*
}
}
// Function {
// $($function)* ($param_name : $param_kind)
// }
Function {
$($function)* ($param_name : $param_kind)
}
// Extract {
// $($extract:tt)* {
// use $nu_data::types::ExtractType;
// let value = $args.expect_nth($($positional_count)*)?;
// <$param_kind>::extract(&value)?
// }
// }
// );
// };
Extract {
$($extract:tt)* {
use $nu_data::types::ExtractType;
let value = $args.expect_nth($($positional_count)*)?;
<$param_kind>::extract(&value)?
}
}
);
};
// ($export:ident as $config_name:tt ( $args:ident , $($command_rest:tt)* ) $body:block) => {
// command!(
// Named { $export $args $body }
// Positional { 0 }
// Rest { $($command_rest)* }
// Signature {
// name: $config_name,
// mandatory_positional: vec![],
// optional_positional: vec![],
// rest_positional: false,
// named: {}
// }
($export:ident as $config_name:tt ( $args:ident , $($command_rest:tt)* ) $body:block) => {
command!(
Named { $export $args $body }
Positional { 0 }
Rest { $($command_rest)* }
Signature {
name: $config_name,
mandatory_positional: vec![],
optional_positional: vec![],
rest_positional: false,
named: {}
}
// Function {
// }
Function {
}
Extract {
}
);
};
}
// Extract {
// }
// );
// };
// }

View File

@ -20,7 +20,7 @@ impl WholeStreamCommand for Command {
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
Ok(OutputStream::one(
UntaggedValue::string(get_full_help(&Command, &args.scope)).into_value(Tag::unknown()),
UntaggedValue::string(get_full_help(&Command, args.scope())).into_value(Tag::unknown()),
))
}
}

View File

@ -37,7 +37,7 @@ 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.clone();
let shell_manager = args.shell_manager();
let (args, _) = args.process()?;
shell_manager.mkdir(args, name)

View File

@ -55,7 +55,7 @@ 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.clone();
let shell_manager = args.shell_manager();
let (args, _) = args.process()?;
shell_manager.mv(args, name)

View File

@ -46,8 +46,8 @@ 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.clone();
let scope = args.scope().clone();
let shell_manager = args.shell_manager();
let (Arguments { load_path }, _) = args.process()?;
if let Some(Tagged {

View File

@ -100,11 +100,11 @@ pub fn get_encoding(opt: Option<Tagged<String>>) -> Result<&'static Encoding, Sh
}
fn open(args: CommandArgs) -> Result<ActionStream, ShellError> {
let scope = args.scope.clone();
let cwd = PathBuf::from(args.shell_manager.path());
let shell_manager = args.shell_manager.clone();
let scope = args.scope().clone();
let shell_manager = args.shell_manager();
let cwd = PathBuf::from(shell_manager.path());
let name = args.call_info.name_tag.clone();
let ctrl_c = args.ctrl_c.clone();
let ctrl_c = args.ctrl_c();
let (
OpenArgs {

View File

@ -35,7 +35,7 @@ the path literal."#
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
Ok(OutputStream::one(
UntaggedValue::string(get_full_help(&Path, &args.scope)).into_value(Tag::unknown()),
UntaggedValue::string(get_full_help(&Path, args.scope())).into_value(Tag::unknown()),
))
}
}

View File

@ -32,7 +32,7 @@ impl WholeStreamCommand for Pwd {
}
pub fn pwd(args: CommandArgs) -> Result<ActionStream, ShellError> {
let shell_manager = args.shell_manager.clone();
let shell_manager = args.shell_manager();
let args = args.evaluate_once()?;
shell_manager.pwd(args)

View File

@ -20,7 +20,7 @@ impl WholeStreamCommand for Command {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
Ok(ActionStream::one(Ok(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()),
))))
}
}

View File

@ -64,7 +64,7 @@ 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.clone();
let shell_manager = args.shell_manager();
let (args, _): (RemoveArgs, _) = args.process()?;
if args.trash.item && args.permanent.item {

View File

@ -2,7 +2,6 @@ use crate::commands::classified::external;
use crate::prelude::*;
use derive_new::new;
use parking_lot::Mutex;
use std::path::PathBuf;
use nu_engine::shell::CdArgs;
@ -75,17 +74,7 @@ impl WholeStreamCommand for RunExternalCommand {
})
.and_then(spanned_expression_to_string)?;
let mut external_context = {
EvaluationContext {
scope: args.scope.clone(),
host: args.host.clone(),
shell_manager: args.shell_manager.clone(),
ctrl_c: args.ctrl_c.clone(),
configs: args.configs.clone(),
current_errors: Arc::new(Mutex::new(vec![])),
windows_drives_previous_cwd: Arc::new(Mutex::new(std::collections::HashMap::new())),
}
};
let mut external_context = args.context.clone();
let is_interactive = self.interactive;
@ -111,7 +100,7 @@ impl WholeStreamCommand for RunExternalCommand {
let result = external_context
.shell_manager
.cd(cd_args, args.call_info.name_tag.clone());
.cd(cd_args, args.call_info.name_tag);
return Ok(result?.to_action_stream());
}

View File

@ -153,19 +153,16 @@ impl WholeStreamCommand for Save {
}
}
fn save(raw_args: CommandArgs) -> Result<OutputStream, ShellError> {
let mut full_path = PathBuf::from(raw_args.shell_manager.path());
let name_tag = raw_args.call_info.name_tag.clone();
let name = raw_args.call_info.name_tag.clone();
let scope = raw_args.scope.clone();
let host = raw_args.host.clone();
let ctrl_c = raw_args.ctrl_c.clone();
let configs = raw_args.configs.clone();
let current_errors = raw_args.current_errors.clone();
let shell_manager = raw_args.shell_manager.clone();
fn save(args: CommandArgs) -> Result<OutputStream, ShellError> {
let shell_manager = args.shell_manager();
let mut full_path = PathBuf::from(shell_manager.path());
let name_tag = args.call_info.name_tag.clone();
let name = args.call_info.name_tag.clone();
let context = args.context.clone();
let scope = args.scope().clone();
let head = raw_args.call_info.args.head.clone();
let args = raw_args.evaluate_once()?;
let head = args.call_info.args.head.clone();
let args = args.evaluate_once()?;
let path: Option<Tagged<PathBuf>> = args.opt(0)?;
let save_raw = args.has_flag("raw");
@ -203,12 +200,8 @@ fn save(raw_args: CommandArgs) -> Result<OutputStream, ShellError> {
if let Some(extension) = full_path.extension() {
let command_name = format!("to {}", extension.to_string_lossy());
if let Some(converter) = scope.get_command(&command_name) {
let new_args = RawCommandArgs {
host,
ctrl_c,
configs,
current_errors,
shell_manager: shell_manager.clone(),
let new_args = CommandArgs {
context,
call_info: UnevaluatedCallInfo {
args: nu_protocol::hir::Call {
head,
@ -219,9 +212,9 @@ fn save(raw_args: CommandArgs) -> Result<OutputStream, ShellError> {
},
name_tag: name_tag.clone(),
},
scope,
input: InputStream::from_stream(input.into_iter()),
};
let mut result = converter.run(new_args.with_input(input))?;
let mut result = converter.run(new_args)?;
let result_vec: Vec<Value> = result.drain_vec();
if converter.is_binary() {
process_binary_return_success!('scope, result_vec, name_tag)

View File

@ -26,12 +26,14 @@ impl WholeStreamCommand for Shells {
fn shells(args: CommandArgs) -> ActionStream {
let mut shells_out = VecDeque::new();
let shell_manager = args.shell_manager();
let tag = args.call_info.name_tag;
let active_index = shell_manager.current_shell.load(Ordering::SeqCst);
for (index, shell) in args.shell_manager.shells.lock().iter().enumerate() {
for (index, shell) in shell_manager.shells.lock().iter().enumerate() {
let mut dict = TaggedDictBuilder::new(&tag);
if index == (*args.shell_manager.current_shell).load(Ordering::SeqCst) {
if index == active_index {
dict.insert_untagged("active", true);
} else {
dict.insert_untagged("active", false);

View File

@ -35,7 +35,7 @@ impl WholeStreamCommand for Sleep {
}
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
let ctrl_c = args.ctrl_c().clone();
let ctrl_c = args.ctrl_c();
let (SleepArgs { duration, rest }, _) = args.process()?;

View File

@ -21,7 +21,7 @@ impl WholeStreamCommand for Command {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
Ok(ActionStream::one(Ok(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()),
))))
}
}

View File

@ -23,7 +23,7 @@ impl WholeStreamCommand for Command {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
Ok(ActionStream::one(ReturnSuccess::value(
UntaggedValue::string(get_full_help(&Command, &args.scope)).into_value(Tag::unknown()),
UntaggedValue::string(get_full_help(&Command, args.scope())).into_value(Tag::unknown()),
)))
}
}

View File

@ -173,7 +173,7 @@ fn values_to_entries(
fn table(args: CommandArgs) -> Result<OutputStream, ShellError> {
let mut args = args.evaluate_once()?;
let configuration = args.configs.lock().global_config();
let configuration = args.configs().lock().global_config();
// Ideally, get_color_config would get all the colors configured in the config.toml
// and create a style based on those settings. However, there are few places where
@ -191,7 +191,7 @@ fn table(args: CommandArgs) -> Result<OutputStream, ShellError> {
let mut delay_slot = None;
let term_width = args.host.lock().width();
let term_width = args.host().lock().width();
#[cfg(feature = "table-pager")]
let pager = Pager::new()

View File

@ -21,7 +21,7 @@ impl WholeStreamCommand for To {
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
Ok(OutputStream::one(
UntaggedValue::string(get_full_help(&To, &args.scope)).into_value(Tag::unknown()),
UntaggedValue::string(get_full_help(&To, args.scope())).into_value(Tag::unknown()),
))
}
}

View File

@ -20,7 +20,7 @@ impl WholeStreamCommand for Url {
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
Ok(ActionStream::one(ReturnSuccess::value(
UntaggedValue::string(get_full_help(&Url, &args.scope)).into_value(Tag::unknown()),
UntaggedValue::string(get_full_help(&Url, args.scope())).into_value(Tag::unknown()),
)))
}
}

View File

@ -220,7 +220,7 @@ fn which(args: CommandArgs) -> Result<OutputStream, ShellError> {
let mut output = vec![];
for app in which_args.applications {
let values = which_single(app, which_args.all, &args.scope);
let values = which_single(app, which_args.all, &args.scope());
output.extend(values);
}

View File

@ -8,7 +8,6 @@ use double_echo::Command as DoubleEcho;
use double_ls::Command as DoubleLs;
use stub_generate::{mock_path, Command as StubOpen};
use nu_engine::basic_evaluation_context;
use nu_errors::ShellError;
use nu_parser::ParserScope;
use nu_protocol::hir::{ClassifiedBlock, ExternalRedirection};
@ -25,7 +24,7 @@ use nu_stream::InputStream;
pub fn test_examples(cmd: Command) -> Result<(), ShellError> {
let examples = cmd.examples();
let base_context = basic_evaluation_context()?;
let base_context = EvaluationContext::basic();
base_context.add_commands(vec![
// Command Doubles
@ -91,7 +90,7 @@ pub fn test_examples(cmd: Command) -> Result<(), ShellError> {
pub fn test(cmd: impl WholeStreamCommand + 'static) -> Result<(), ShellError> {
let examples = cmd.examples();
let base_context = basic_evaluation_context()?;
let base_context = EvaluationContext::basic();
base_context.add_commands(vec![
whole_stream_command(Math),
@ -150,7 +149,7 @@ pub fn test(cmd: impl WholeStreamCommand + 'static) -> Result<(), ShellError> {
pub fn test_anchors(cmd: Command) -> Result<(), ShellError> {
let examples = cmd.examples();
let base_context = basic_evaluation_context()?;
let base_context = EvaluationContext::basic();
base_context.add_commands(vec![
// Minimal restricted commands to aid in testing

View File

@ -16,9 +16,8 @@ pub(crate) use nu_data::value;
pub(crate) use nu_engine::EvaluationContext;
pub(crate) use nu_engine::Example;
pub(crate) use nu_engine::Host;
pub(crate) use nu_engine::RawCommandArgs;
pub(crate) use nu_engine::RunnableContext;
pub(crate) use nu_engine::{get_full_help, CommandArgs, Scope, WholeStreamCommand};
pub(crate) use nu_engine::{RunnableContext, RunnableContextWithoutInput};
pub(crate) use nu_parser::ParserScope;
pub(crate) use nu_protocol::{out, row};
pub(crate) use nu_source::{AnchorLocation, PrettyDebug, Span, SpannedItem, Tag, TaggedItem};