mirror of
https://github.com/nushell/nushell.git
synced 2025-01-10 08:18:57 +01:00
WIP
This commit is contained in:
parent
2da12aed56
commit
70f9e355fd
@ -500,7 +500,7 @@ fn classify_command(
|
|||||||
let config = command.config();
|
let config = command.config();
|
||||||
let scope = Scope::empty();
|
let scope = Scope::empty();
|
||||||
|
|
||||||
trace!("classifying {:?}", config);
|
trace!(target: "nu::build_pipeline", "classifying {:?}", config);
|
||||||
|
|
||||||
let args = config.evaluate_args(call, context, &scope, source)?;
|
let args = config.evaluate_args(call, context, &scope, source)?;
|
||||||
|
|
||||||
|
@ -87,6 +87,7 @@ crate enum ClassifiedCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ClassifiedCommand {
|
impl ClassifiedCommand {
|
||||||
|
#[allow(unused)]
|
||||||
pub fn span(&self) -> Span {
|
pub fn span(&self) -> Span {
|
||||||
match self {
|
match self {
|
||||||
ClassifiedCommand::Expr(token) => token.span(),
|
ClassifiedCommand::Expr(token) => token.span(),
|
||||||
@ -126,12 +127,13 @@ impl InternalCommand {
|
|||||||
input: ClassifiedInputStream,
|
input: ClassifiedInputStream,
|
||||||
) -> Result<InputStream, ShellError> {
|
) -> Result<InputStream, ShellError> {
|
||||||
if log_enabled!(log::Level::Trace) {
|
if log_enabled!(log::Level::Trace) {
|
||||||
trace!("->");
|
trace!(target: "nu::run::internal", "->");
|
||||||
trace!("{}", self.command.name());
|
trace!(target: "nu::run::internal", "{}", self.command.name());
|
||||||
trace!("{:?}", self.args.debug());
|
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 =
|
let result =
|
||||||
context.run_command(self.command, self.name_span.clone(), self.args, objects)?;
|
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 inputs: Vec<Spanned<Value>> = input.objects.into_vec().await;
|
||||||
let name_span = self.name_span.clone();
|
let name_span = self.name_span.clone();
|
||||||
|
|
||||||
trace!("-> {}", self.name);
|
trace!(target: "nu::run::external", "-> {}", self.name);
|
||||||
trace!("inputs = {:?}", inputs);
|
trace!(target: "nu::run::external", "inputs = {:?}", inputs);
|
||||||
|
|
||||||
let mut arg_string = format!("{}", self.name);
|
let mut arg_string = format!("{}", self.name);
|
||||||
for arg in &self.args {
|
for arg in &self.args {
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
use crate::object::{Dictionary, Primitive, SpannedDictBuilder, Value};
|
use crate::object::{Dictionary, Primitive, SpannedDictBuilder, Value};
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use indexmap::IndexMap;
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
fn convert_ini_second_to_nu_value(
|
fn convert_ini_second_to_nu_value(
|
||||||
|
@ -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
|
// mandatory positional argument
|
||||||
(
|
(
|
||||||
Named { $export:ident $args:ident $body:block }
|
Named { $export:ident $args:ident $body:block }
|
||||||
@ -246,7 +301,7 @@ macro_rules! command {
|
|||||||
CommandConfig {
|
CommandConfig {
|
||||||
name: $config_name,
|
name: $config_name,
|
||||||
mandatory_positional: vec![ $($mandatory_positional)* $crate::parser::registry::PositionalType::mandatory(
|
mandatory_positional: vec![ $($mandatory_positional)* $crate::parser::registry::PositionalType::mandatory(
|
||||||
stringify!($param_name), stringify!($param_kind)
|
stringify!($param_name)
|
||||||
), ],
|
), ],
|
||||||
optional_positional: vec![ $($optional_positional)* ],
|
optional_positional: vec![ $($optional_positional)* ],
|
||||||
rest_positional: $rest_positional,
|
rest_positional: $rest_positional,
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
use crate::errors::ShellError;
|
use crate::errors::ShellError;
|
||||||
use crate::object::base::select_fields;
|
use crate::object::base::select_fields;
|
||||||
use crate::object::Value;
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
pub fn pick(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
pub fn pick(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
use crate::errors::ShellError;
|
use crate::errors::ShellError;
|
||||||
use crate::object::process::process_dict;
|
use crate::object::process::process_dict;
|
||||||
use crate::object::Value;
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use sysinfo::{RefreshKind, SystemExt};
|
use sysinfo::{RefreshKind, SystemExt};
|
||||||
|
|
||||||
@ -11,7 +10,7 @@ pub fn ps(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
|
|
||||||
let list = list
|
let list = list
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|(item, process)| process_dict(process, args.name_span))
|
.map(|(_, process)| process_dict(process, args.name_span))
|
||||||
.collect::<VecDeque<_>>();
|
.collect::<VecDeque<_>>();
|
||||||
|
|
||||||
Ok(list.from_input_stream())
|
Ok(list.from_input_stream())
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
use crate::errors::ShellError;
|
use crate::errors::ShellError;
|
||||||
use crate::object::base::reject_fields;
|
use crate::object::base::reject_fields;
|
||||||
use crate::object::Value;
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
pub fn reject(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
pub fn reject(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
|
@ -3,7 +3,6 @@ use crate::object::base::OF64;
|
|||||||
use crate::object::SpannedDictBuilder;
|
use crate::object::SpannedDictBuilder;
|
||||||
use crate::object::{Primitive, Value};
|
use crate::object::{Primitive, Value};
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use log::trace;
|
|
||||||
use sys_info::*;
|
use sys_info::*;
|
||||||
use sysinfo::{ComponentExt, DiskExt, NetworkExt, RefreshKind, SystemExt};
|
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));
|
network_idx.insert("outgoing", Value::bytes(outgoing));
|
||||||
idx.insert_spanned("network", network_idx);
|
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())
|
Ok(stream.from_input_stream())
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
use crate::errors::ShellError;
|
use crate::errors::ShellError;
|
||||||
use crate::object::{Primitive, Value};
|
use crate::object::Value;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
// TODO: "Amount remaining" wrapper
|
// TODO: "Amount remaining" wrapper
|
||||||
|
|
||||||
pub fn trim(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
pub fn trim(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
let input = args.input;
|
let input = args.input;
|
||||||
let span = args.name_span;
|
|
||||||
|
|
||||||
Ok(input
|
Ok(input
|
||||||
.values
|
.values
|
||||||
@ -14,13 +13,5 @@ pub fn trim(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
let string = String::extract(&v)?;
|
let string = String::extract(&v)?;
|
||||||
ReturnSuccess::value(Value::string(string.trim()).spanned(v.span))
|
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())
|
.to_output_stream())
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ use log::trace;
|
|||||||
|
|
||||||
command! {
|
command! {
|
||||||
Where as where(args, condition: Block) {
|
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| {
|
input.values.filter_map(move |item| {
|
||||||
let result = condition.invoke(&item);
|
let result = condition.invoke(&item);
|
||||||
|
@ -53,15 +53,15 @@ fn trace_step<'a, T: Debug>(
|
|||||||
name: &str,
|
name: &str,
|
||||||
block: impl FnOnce(NomSpan<'a>) -> IResult<NomSpan<'a>, T>,
|
block: impl FnOnce(NomSpan<'a>) -> IResult<NomSpan<'a>, T>,
|
||||||
) -> IResult<NomSpan<'a>, T> {
|
) -> IResult<NomSpan<'a>, T> {
|
||||||
trace!("+ before {} @ {:?}", name, input);
|
trace!(target: "nu::lite_parse", "+ before {} @ {:?}", name, input);
|
||||||
match block(input) {
|
match block(input) {
|
||||||
Ok((input, result)) => {
|
Ok((input, result)) => {
|
||||||
trace!("after {} @ {:?} -> {:?}", name, input, result);
|
trace!(target: "nu::lite_parse", "after {} @ {:?} -> {:?}", name, input, result);
|
||||||
Ok((input, result))
|
Ok((input, result))
|
||||||
}
|
}
|
||||||
|
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
trace!("- failed {} :: {:?}", name, e);
|
trace!(target: "nu::lite_parse", "- failed {} :: {:?}", name, e);
|
||||||
Err(e)
|
Err(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,7 +78,7 @@ fn parse_command_tail(
|
|||||||
trace_remaining("nodes", tail.clone(), source);
|
trace_remaining("nodes", tail.clone(), source);
|
||||||
|
|
||||||
for (name, kind) in config.named() {
|
for (name, kind) in config.named() {
|
||||||
trace!("looking for {} : {:?}", name, kind);
|
trace!(target: "nu::parse", "looking for {} : {:?}", name, kind);
|
||||||
|
|
||||||
match kind {
|
match kind {
|
||||||
NamedType::Switch => {
|
NamedType::Switch => {
|
||||||
|
@ -13,8 +13,8 @@ macro_rules! stream {
|
|||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! trace_stream {
|
macro_rules! trace_stream {
|
||||||
($desc:tt = $expr:expr) => {{
|
(target: $target:tt, $desc:tt = $expr:expr) => {{
|
||||||
if log::log_enabled!(target: "nu::trace_stream", log::Level::Trace) {
|
if log::log_enabled!(target: $target, log::Level::Trace) {
|
||||||
use futures::stream::StreamExt;
|
use futures::stream::StreamExt;
|
||||||
// Blocking is generally quite bad, but this is for debugging
|
// Blocking is generally quite bad, but this is for debugging
|
||||||
// let mut local = futures::executor::LocalPool::new();
|
// 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: Vec<_> = futures::executor::block_on($expr.into_vec());
|
||||||
|
|
||||||
let objects = $expr.values.inspect(|o| {
|
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())
|
$crate::stream::InputStream::from_stream(objects.boxed())
|
||||||
|
Loading…
Reference in New Issue
Block a user