diff --git a/src/cli.rs b/src/cli.rs index 4b5d5c6813..5da609a3f2 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -500,7 +500,7 @@ fn classify_command( let config = command.config(); let scope = Scope::empty(); - trace!("classifying {:?}", config); + trace!(target: "nu::build_pipeline", "classifying {:?}", config); let args = config.evaluate_args(call, context, &scope, source)?; diff --git a/src/commands/classified.rs b/src/commands/classified.rs index 93ef2b9782..477e05bb71 100644 --- a/src/commands/classified.rs +++ b/src/commands/classified.rs @@ -87,6 +87,7 @@ crate enum ClassifiedCommand { } impl ClassifiedCommand { + #[allow(unused)] pub fn span(&self) -> Span { match self { ClassifiedCommand::Expr(token) => token.span(), @@ -126,12 +127,13 @@ impl InternalCommand { input: ClassifiedInputStream, ) -> Result { if log_enabled!(log::Level::Trace) { - trace!("->"); - trace!("{}", self.command.name()); - trace!("{:?}", self.args.debug()); + trace!(target: "nu::run::internal", "->"); + trace!(target: "nu::run::internal", "{}", self.command.name()); + trace!(target: "nu::run::internal", "{:?}", self.args.debug()); } - let objects: InputStream = trace_stream!("input" = input.objects); + let objects: InputStream = + trace_stream!(target: "nu::trace_stream::internal", "input" = input.objects); let result = context.run_command(self.command, self.name_span.clone(), self.args, objects)?; @@ -203,8 +205,8 @@ impl ExternalCommand { let inputs: Vec> = input.objects.into_vec().await; let name_span = self.name_span.clone(); - trace!("-> {}", self.name); - trace!("inputs = {:?}", inputs); + trace!(target: "nu::run::external", "-> {}", self.name); + trace!(target: "nu::run::external", "inputs = {:?}", inputs); let mut arg_string = format!("{}", self.name); for arg in &self.args { diff --git a/src/commands/from_ini.rs b/src/commands/from_ini.rs index 863c2d6196..7352d4c0db 100644 --- a/src/commands/from_ini.rs +++ b/src/commands/from_ini.rs @@ -1,6 +1,5 @@ use crate::object::{Dictionary, Primitive, SpannedDictBuilder, Value}; use crate::prelude::*; -use indexmap::IndexMap; use std::collections::HashMap; fn convert_ini_second_to_nu_value( diff --git a/src/commands/macros.rs b/src/commands/macros.rs index 5a4e9e2d14..3662378fbb 100644 --- a/src/commands/macros.rs +++ b/src/commands/macros.rs @@ -215,6 +215,61 @@ macro_rules! command { ); }; + // mandatory positional block + ( + Named { $export:ident $args:ident $body:block } + Positional { $($positional_count:tt)* } + Rest { , $param_name:ident : Block $($rest:tt)* } + CommandConfig { + 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)* } + CommandConfig { + name: $config_name, + mandatory_positional: vec![ $($mandatory_positional)* $crate::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) + } + + Extract { + $($extract:tt)* { + use $crate::object::types::ExtractType; + let value = $args.expect_nth($($positional_count)*)?; + Block::extract(value)? + } + } + ); + }; + + // mandatory positional argument ( Named { $export:ident $args:ident $body:block } @@ -246,7 +301,7 @@ macro_rules! command { CommandConfig { name: $config_name, mandatory_positional: vec![ $($mandatory_positional)* $crate::parser::registry::PositionalType::mandatory( - stringify!($param_name), stringify!($param_kind) + stringify!($param_name) ), ], optional_positional: vec![ $($optional_positional)* ], rest_positional: $rest_positional, diff --git a/src/commands/pick.rs b/src/commands/pick.rs index d9f42aa6b1..0d53ce9942 100644 --- a/src/commands/pick.rs +++ b/src/commands/pick.rs @@ -1,6 +1,5 @@ use crate::errors::ShellError; use crate::object::base::select_fields; -use crate::object::Value; use crate::prelude::*; pub fn pick(args: CommandArgs) -> Result { diff --git a/src/commands/ps.rs b/src/commands/ps.rs index 5336ec97f0..14b9ba27fa 100644 --- a/src/commands/ps.rs +++ b/src/commands/ps.rs @@ -1,6 +1,5 @@ use crate::errors::ShellError; use crate::object::process::process_dict; -use crate::object::Value; use crate::prelude::*; use sysinfo::{RefreshKind, SystemExt}; @@ -11,7 +10,7 @@ pub fn ps(args: CommandArgs) -> Result { let list = list .into_iter() - .map(|(item, process)| process_dict(process, args.name_span)) + .map(|(_, process)| process_dict(process, args.name_span)) .collect::>(); Ok(list.from_input_stream()) diff --git a/src/commands/reject.rs b/src/commands/reject.rs index fc53aaea9c..362df135db 100644 --- a/src/commands/reject.rs +++ b/src/commands/reject.rs @@ -1,6 +1,5 @@ use crate::errors::ShellError; use crate::object::base::reject_fields; -use crate::object::Value; use crate::prelude::*; pub fn reject(args: CommandArgs) -> Result { diff --git a/src/commands/sysinfo.rs b/src/commands/sysinfo.rs index 3a7cd5646c..73fda3fe02 100644 --- a/src/commands/sysinfo.rs +++ b/src/commands/sysinfo.rs @@ -3,7 +3,6 @@ use crate::object::base::OF64; use crate::object::SpannedDictBuilder; use crate::object::{Primitive, Value}; use crate::prelude::*; -use log::trace; use sys_info::*; use sysinfo::{ComponentExt, DiskExt, NetworkExt, RefreshKind, SystemExt}; @@ -127,7 +126,7 @@ pub fn sysinfo(args: CommandArgs) -> Result { network_idx.insert("outgoing", Value::bytes(outgoing)); idx.insert_spanned("network", network_idx); - let mut stream = stream![idx.into_spanned_value()]; + let stream = stream![idx.into_spanned_value()]; Ok(stream.from_input_stream()) } diff --git a/src/commands/trim.rs b/src/commands/trim.rs index e4d66ffd2e..e0f2d42b0c 100644 --- a/src/commands/trim.rs +++ b/src/commands/trim.rs @@ -1,12 +1,11 @@ use crate::errors::ShellError; -use crate::object::{Primitive, Value}; +use crate::object::Value; use crate::prelude::*; // TODO: "Amount remaining" wrapper pub fn trim(args: CommandArgs) -> Result { let input = args.input; - let span = args.name_span; Ok(input .values @@ -14,13 +13,5 @@ pub fn trim(args: CommandArgs) -> Result { let string = String::extract(&v)?; ReturnSuccess::value(Value::string(string.trim()).spanned(v.span)) }) - // Value::Primitive(Primitive::String(s)) => { - // ReturnSuccess::value(Value::Primitive(Primitive::String(s.trim().into()))) - // } - // _ => Err(ShellError::maybe_labeled_error( - // "Expected string values from pipeline", - // "expects strings from pipeline", - // span, - // )), .to_output_stream()) } diff --git a/src/commands/where_.rs b/src/commands/where_.rs index d5d9f6bb61..d8f68c2b62 100644 --- a/src/commands/where_.rs +++ b/src/commands/where_.rs @@ -6,7 +6,7 @@ use log::trace; command! { Where as where(args, condition: Block) { - let input: InputStream = trace_stream!("where input" = args.input); + let input: InputStream = trace_stream!(target: "nu::trace_stream::where", "where input" = args.input); input.values.filter_map(move |item| { let result = condition.invoke(&item); diff --git a/src/parser/parse/parser.rs b/src/parser/parse/parser.rs index 7c25ff04c5..795b980ee2 100644 --- a/src/parser/parse/parser.rs +++ b/src/parser/parse/parser.rs @@ -53,15 +53,15 @@ fn trace_step<'a, T: Debug>( name: &str, block: impl FnOnce(NomSpan<'a>) -> IResult, T>, ) -> IResult, T> { - trace!("+ before {} @ {:?}", name, input); + trace!(target: "nu::lite_parse", "+ before {} @ {:?}", name, input); match block(input) { Ok((input, result)) => { - trace!("after {} @ {:?} -> {:?}", name, input, result); + trace!(target: "nu::lite_parse", "after {} @ {:?} -> {:?}", name, input, result); Ok((input, result)) } Err(e) => { - trace!("- failed {} :: {:?}", name, e); + trace!(target: "nu::lite_parse", "- failed {} :: {:?}", name, e); Err(e) } } diff --git a/src/parser/parse_command.rs b/src/parser/parse_command.rs index 8c7d5e7cfe..fc63500b45 100644 --- a/src/parser/parse_command.rs +++ b/src/parser/parse_command.rs @@ -78,7 +78,7 @@ fn parse_command_tail( trace_remaining("nodes", tail.clone(), source); for (name, kind) in config.named() { - trace!("looking for {} : {:?}", name, kind); + trace!(target: "nu::parse", "looking for {} : {:?}", name, kind); match kind { NamedType::Switch => { diff --git a/src/prelude.rs b/src/prelude.rs index 40ef6eb098..67454939c6 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -13,8 +13,8 @@ macro_rules! stream { #[macro_export] macro_rules! trace_stream { - ($desc:tt = $expr:expr) => {{ - if log::log_enabled!(target: "nu::trace_stream", log::Level::Trace) { + (target: $target:tt, $desc:tt = $expr:expr) => {{ + if log::log_enabled!(target: $target, log::Level::Trace) { use futures::stream::StreamExt; // Blocking is generally quite bad, but this is for debugging // let mut local = futures::executor::LocalPool::new(); @@ -22,7 +22,7 @@ macro_rules! trace_stream { // let objects: Vec<_> = futures::executor::block_on($expr.into_vec()); let objects = $expr.values.inspect(|o| { - trace!(target: "nu::trace_stream", "{} = {:#?}", $desc, o.debug()); + trace!(target: $target, "{} = {:#?}", $desc, o.debug()); }); $crate::stream::InputStream::from_stream(objects.boxed())