This commit is contained in:
Yehuda Katz 2019-07-12 12:22:08 -07:00
parent 2da12aed56
commit 70f9e355fd
13 changed files with 76 additions and 33 deletions

View File

@ -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)?;

View File

@ -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<InputStream, ShellError> {
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<Spanned<Value>> = 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 {

View File

@ -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(

View File

@ -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,

View File

@ -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<OutputStream, ShellError> {

View File

@ -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<OutputStream, ShellError> {
let list = list
.into_iter()
.map(|(item, process)| process_dict(process, args.name_span))
.map(|(_, process)| process_dict(process, args.name_span))
.collect::<VecDeque<_>>();
Ok(list.from_input_stream())

View File

@ -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<OutputStream, ShellError> {

View File

@ -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<OutputStream, ShellError> {
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())
}

View File

@ -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<OutputStream, ShellError> {
let input = args.input;
let span = args.name_span;
Ok(input
.values
@ -14,13 +13,5 @@ pub fn trim(args: CommandArgs) -> Result<OutputStream, ShellError> {
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())
}

View File

@ -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);

View File

@ -53,15 +53,15 @@ fn trace_step<'a, T: Debug>(
name: &str,
block: impl FnOnce(NomSpan<'a>) -> IResult<NomSpan<'a>, T>,
) -> IResult<NomSpan<'a>, 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)
}
}

View File

@ -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 => {

View File

@ -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())