mirror of
https://github.com/nushell/nushell.git
synced 2025-04-30 16:14:27 +02:00
* move commands, futures.rs, script.rs, utils * move over maybe_print_errors * add nu_command crate references to nu_cli * in commands.rs open up to pub mod from pub(crate) * nu-cli, nu-command, and nu tests are now passing * cargo fmt * clean up nu-cli/src/prelude.rs * code cleanup * for some reason lex.rs was not formatted, may be causing my error * remove mod completion from lib.rs which was not being used along with quickcheck macros * add in allow unused imports * comment out one failing external test; comment out one failing internal test * revert commenting out failing tests; something else might be going on; someone with a windows machine should check and see what is going on with these failing windows tests * Update Cargo.toml Extend the optional features to nu-command Co-authored-by: Jonathan Turner <jonathandturner@users.noreply.github.com>
107 lines
2.9 KiB
Rust
107 lines
2.9 KiB
Rust
#[macro_export]
|
|
macro_rules! return_err {
|
|
($expr:expr) => {
|
|
match $expr {
|
|
Err(_) => return,
|
|
Ok(expr) => expr,
|
|
};
|
|
};
|
|
}
|
|
|
|
#[macro_export]
|
|
macro_rules! stream {
|
|
($($expr:expr),*) => {{
|
|
let mut v = VecDeque::new();
|
|
|
|
$(
|
|
v.push_back($expr);
|
|
)*
|
|
|
|
v
|
|
}}
|
|
}
|
|
|
|
#[macro_export]
|
|
macro_rules! trace_out_stream {
|
|
(target: $target:tt, $desc:tt = $expr:expr) => {{
|
|
if log::log_enabled!(target: $target, log::Level::Trace) {
|
|
use futures::stream::StreamExt;
|
|
|
|
let objects = $expr.inspect(move |o| {
|
|
trace!(
|
|
target: $target,
|
|
"{} = {}",
|
|
$desc,
|
|
match o {
|
|
Err(err) => format!("{:?}", err),
|
|
Ok(value) => value.display(),
|
|
}
|
|
);
|
|
});
|
|
|
|
nu_stream::OutputStream::new(objects)
|
|
} else {
|
|
$expr
|
|
}
|
|
}};
|
|
}
|
|
|
|
pub(crate) use crate::commands::command::RunnableContext;
|
|
pub(crate) use async_trait::async_trait;
|
|
pub(crate) use bigdecimal::BigDecimal;
|
|
pub(crate) use futures::{Stream, StreamExt};
|
|
pub(crate) use indexmap::{indexmap, IndexMap};
|
|
pub(crate) use itertools::Itertools;
|
|
pub(crate) use nu_data::config;
|
|
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::ShellManager;
|
|
pub(crate) use nu_engine::{get_help, CommandArgs, Scope, WholeStreamCommand};
|
|
pub(crate) use nu_parser::ParserScope;
|
|
pub(crate) use nu_protocol::{out, row};
|
|
pub(crate) use nu_source::{AnchorLocation, PrettyDebug, Span, SpannedItem, Tag, TaggedItem, Text};
|
|
pub(crate) use nu_stream::ToInputStream;
|
|
pub(crate) use nu_stream::{InputStream, Interruptible, OutputStream};
|
|
pub(crate) use nu_value_ext::ValueExt;
|
|
pub(crate) use num_bigint::BigInt;
|
|
pub(crate) use num_traits::cast::ToPrimitive;
|
|
pub(crate) use serde::Deserialize;
|
|
pub(crate) use std::collections::VecDeque;
|
|
pub(crate) use std::future::Future;
|
|
pub(crate) use std::sync::atomic::{AtomicBool, Ordering};
|
|
pub(crate) use std::sync::Arc;
|
|
|
|
pub trait FromInputStream {
|
|
fn from_input_stream(self) -> OutputStream;
|
|
}
|
|
|
|
impl<T> FromInputStream for T
|
|
where
|
|
T: Stream<Item = nu_protocol::Value> + Send + 'static,
|
|
{
|
|
fn from_input_stream(self) -> OutputStream {
|
|
OutputStream {
|
|
values: self.map(nu_protocol::ReturnSuccess::value).boxed(),
|
|
}
|
|
}
|
|
}
|
|
|
|
pub trait ToOutputStream {
|
|
fn to_output_stream(self) -> OutputStream;
|
|
}
|
|
|
|
impl<T, U> ToOutputStream for T
|
|
where
|
|
T: Stream<Item = U> + Send + 'static,
|
|
U: Into<nu_protocol::ReturnValue>,
|
|
{
|
|
fn to_output_stream(self) -> OutputStream {
|
|
OutputStream {
|
|
values: self.map(|item| item.into()).boxed(),
|
|
}
|
|
}
|
|
}
|