nu-cli refactor moving commands into their own crate nu-command (#2910)

* 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>
This commit is contained in:
Michael Angerman 2021-01-11 20:59:53 -08:00 committed by GitHub
parent 7d07881d96
commit d06f457b2a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
374 changed files with 434 additions and 99 deletions

117
Cargo.lock generated
View File

@ -3043,6 +3043,7 @@ dependencies = [
"itertools",
"log 0.4.11",
"nu-cli",
"nu-command",
"nu-data",
"nu-engine",
"nu-errors",
@ -3076,6 +3077,110 @@ dependencies = [
[[package]]
name = "nu-cli"
version = "0.25.2"
dependencies = [
"Inflector",
"ansi_term 0.12.1",
"arboard",
"async-recursion",
"async-trait",
"base64 0.13.0",
"bigdecimal",
"byte-unit",
"bytes 0.5.6",
"calamine",
"chrono",
"chrono-tz",
"clap",
"codespan-reporting",
"csv",
"ctrlc",
"derive-new",
"directories 3.0.1",
"dirs 3.0.1",
"dtparse",
"dunce",
"eml-parser",
"encoding_rs",
"filesize",
"fs_extra",
"futures 0.3.8",
"futures-util",
"futures_codec",
"getset",
"git2",
"glob",
"heim",
"htmlescape",
"ical",
"ichwh",
"indexmap",
"itertools",
"lazy_static 1.4.0",
"log 0.4.11",
"meval",
"nu-command",
"nu-data",
"nu-engine",
"nu-errors",
"nu-json",
"nu-parser",
"nu-plugin",
"nu-protocol",
"nu-source",
"nu-stream",
"nu-table",
"nu-test-support",
"nu-value-ext",
"num-bigint 0.3.1",
"num-format",
"num-traits 0.2.14",
"parking_lot 0.11.1",
"pin-utils",
"pretty-hex",
"ptree",
"query_interface",
"quick-xml 0.20.0",
"quickcheck",
"quickcheck_macros",
"rand 0.7.3",
"rayon",
"regex 1.4.2",
"roxmltree",
"rusqlite",
"rust-embed",
"rustyline",
"serde 1.0.118",
"serde_bytes",
"serde_ini",
"serde_json",
"serde_urlencoded 0.7.0",
"serde_yaml",
"sha2 0.9.2",
"shadow-rs",
"shellexpand",
"strip-ansi-escapes",
"sxd-document",
"sxd-xpath",
"tempfile",
"term",
"term_size",
"termcolor",
"titlecase",
"toml",
"trash",
"umask",
"unicode-segmentation",
"uom",
"url",
"users",
"uuid",
"which",
"zip",
]
[[package]]
name = "nu-command"
version = "0.25.2"
dependencies = [
"Inflector",
"ansi_term 0.12.1",
@ -3176,18 +3281,6 @@ dependencies = [
"zip",
]
[[package]]
name = "nu-core-commands"
version = "0.25.2"
dependencies = [
"async-trait",
"eml-parser",
"nu-errors",
"nu-protocol",
"nu-source",
"serde 1.0.118",
]
[[package]]
name = "nu-data"
version = "0.25.2"

View File

@ -19,6 +19,7 @@ members = ["crates/*/"]
[dependencies]
nu-cli = {version = "0.25.2", path = "./crates/nu-cli"}
nu-command = {version = "0.25.2", path = "./crates/nu-command"}
nu-data = {version = "0.25.2", path = "./crates/nu-data"}
nu-engine = {version = "0.25.2", path = "./crates/nu-engine"}
nu-errors = {version = "0.25.2", path = "./crates/nu-errors"}
@ -62,15 +63,15 @@ nu-test-support = {version = "0.25.2", path = "./crates/nu-test-support"}
[build-dependencies]
[features]
ctrlc-support = ["nu-cli/ctrlc"]
directories-support = ["nu-cli/directories", "nu-cli/dirs", "nu-data/directories", "nu-data/dirs"]
git-support = ["nu-cli/git2"]
ptree-support = ["nu-cli/ptree"]
rich-benchmark = ["nu-cli/rich-benchmark"]
rustyline-support = ["nu-cli/rustyline-support"]
term-support = ["nu-cli/term"]
uuid-support = ["nu-cli/uuid_crate"]
which-support = ["nu-cli/ichwh", "nu-cli/which"]
ctrlc-support = ["nu-cli/ctrlc", "nu-command/ctrlc"]
directories-support = ["nu-cli/directories", "nu-cli/dirs", "nu-command/directories", "nu-command/dirs", "nu-data/directories", "nu-data/dirs"]
git-support = ["nu-cli/git2", "nu-command/git2"]
ptree-support = ["nu-cli/ptree", "nu-command/ptree"]
rich-benchmark = ["nu-cli/rich-benchmark", "nu-command/rich-benchmark"]
rustyline-support = ["nu-cli/rustyline-support", "nu-command/rustyline-support"]
term-support = ["nu-cli/term", "nu-command/term"]
uuid-support = ["nu-cli/uuid_crate", "nu-command/uuid_crate"]
which-support = ["nu-cli/ichwh", "nu-cli/which", "nu-command/ichwh", "nu-command/which"]
default = [
"sys",
@ -106,18 +107,18 @@ post = ["nu_plugin_post"]
ps = ["nu_plugin_ps"]
sys = ["nu_plugin_sys"]
textview = ["nu_plugin_textview"]
zip-support = ["nu-cli/zip"]
zip-support = ["nu-cli/zip", "nu-command/zip"]
# Extra
binaryview = ["nu_plugin_binaryview"]
bson = ["nu_plugin_from_bson", "nu_plugin_to_bson"]
chart = ["nu_plugin_chart"]
clipboard-cli = ["nu-cli/clipboard-cli"]
clipboard-cli = ["nu-cli/clipboard-cli", "nu-command/clipboard-cli"]
s3 = ["nu_plugin_s3"]
selector = ["nu_plugin_selector"]
sqlite = ["nu_plugin_from_sqlite", "nu_plugin_to_sqlite"]
start = ["nu_plugin_start"]
trash-support = ["nu-cli/trash-support"]
trash-support = ["nu-cli/trash-support", "nu-command/trash-support"]
tree = ["nu_plugin_tree"]
xpath = ["nu_plugin_xpath"]

View File

@ -11,6 +11,7 @@ version = "0.25.2"
doctest = false
[dependencies]
nu-command = {version = "0.25.2", path = "../nu-command"}
nu-data = {version = "0.25.2", path = "../nu-data"}
nu-engine = {version = "0.25.2", path = "../nu-engine"}
nu-errors = {version = "0.25.2", path = "../nu-errors"}

View File

@ -1,10 +1,12 @@
use crate::commands::default_context::create_default_context;
use crate::line_editor::configure_ctrl_c;
use nu_command::commands::default_context::create_default_context;
#[allow(unused_imports)]
use nu_command::maybe_print_errors;
use nu_engine::run_block;
use nu_engine::EvaluationContext;
#[allow(unused_imports)]
pub(crate) use crate::script::{process_script, LineResult};
pub(crate) use nu_command::script::{process_script, LineResult};
#[cfg(feature = "rustyline-support")]
use crate::line_editor::{
@ -19,7 +21,7 @@ use nu_stream::InputStream;
#[allow(unused_imports)]
use std::sync::atomic::Ordering;
use crate::script::{print_err, run_script_standalone};
use nu_command::script::{print_err, run_script_standalone};
#[cfg(feature = "rustyline-support")]
use rustyline::{self, error::ReadlineError};
@ -64,21 +66,6 @@ pub fn search_paths() -> Vec<std::path::PathBuf> {
search_paths
}
pub fn maybe_print_errors(context: &EvaluationContext, source: Text) -> bool {
let errors = context.current_errors.clone();
let mut errors = errors.lock();
if errors.len() > 0 {
let error = errors[0].clone();
*errors = vec![];
crate::script::print_err(error, &source);
true
} else {
false
}
}
pub async fn run_script_file(
file_contents: String,
redirect_stdin: bool,

View File

@ -1,6 +1,5 @@
use crate::commands;
use commands::autoenv;
use indexmap::{IndexMap, IndexSet};
use nu_command::commands::autoenv;
use nu_errors::ShellError;
use serde::Deserialize;
use std::env::*;

View File

@ -14,32 +14,25 @@ extern crate quickcheck;
extern crate quickcheck_macros;
mod cli;
mod commands;
#[cfg(feature = "rustyline-support")]
mod completion;
mod env;
mod format;
mod futures;
#[cfg(feature = "rustyline-support")]
mod git;
#[cfg(feature = "rustyline-support")]
mod keybinding;
mod line_editor;
pub mod script;
mod shell;
pub mod types;
pub mod utils;
#[cfg(test)]
mod examples;
#[cfg(feature = "rustyline-support")]
pub use crate::cli::cli;
pub use crate::cli::{parse_and_eval, register_plugins, run_script_file};
pub use crate::commands::default_context::create_default_context;
pub use crate::env::environment_syncer::EnvironmentSyncer;
pub use nu_command::commands::default_context::create_default_context;
pub use nu_data::config;
pub use nu_data::dict::TaggedListBuilder;
pub use nu_data::primitive;

View File

@ -5,7 +5,7 @@ use std::error::Error;
use crate::prelude::*;
#[allow(unused_imports)]
use crate::script::LineResult;
use nu_command::script::LineResult;
#[cfg(feature = "rustyline-support")]
use crate::shell::Helper;

View File

@ -46,36 +46,17 @@ macro_rules! trace_out_stream {
}};
}
pub(crate) use nu_protocol::{out, outln, row};
pub(crate) use crate::cli::maybe_print_errors;
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};
#[allow(unused_imports)]
pub(crate) use nu_errors::ShellError;
pub(crate) use nu_parser::ParserScope;
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};
#[allow(unused_imports)]
pub(crate) use nu_protocol::outln;
pub(crate) use nu_stream::OutputStream;
#[allow(unused_imports)]
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;
#[allow(unused_imports)]
pub(crate) use std::sync::atomic::Ordering;
pub trait FromInputStream {
fn from_input_stream(self) -> OutputStream;

View File

@ -0,0 +1,134 @@
[package]
authors = ["The Nu Project Contributors"]
build = "build.rs"
description = "CLI for nushell"
edition = "2018"
license = "MIT"
name = "nu-command"
version = "0.25.2"
[lib]
doctest = false
[dependencies]
nu-data = {version = "0.25.2", path = "../nu-data"}
nu-engine = {version = "0.25.2", path = "../nu-engine"}
nu-errors = {version = "0.25.2", path = "../nu-errors"}
nu-json = {version = "0.25.2", path = "../nu-json"}
nu-parser = {version = "0.25.2", path = "../nu-parser"}
nu-plugin = {version = "0.25.2", path = "../nu-plugin"}
nu-protocol = {version = "0.25.2", path = "../nu-protocol"}
nu-source = {version = "0.25.2", path = "../nu-source"}
nu-stream = {version = "0.25.2", path = "../nu-stream"}
nu-table = {version = "0.25.2", path = "../nu-table"}
nu-test-support = {version = "0.25.2", path = "../nu-test-support"}
nu-value-ext = {version = "0.25.2", path = "../nu-value-ext"}
Inflector = "0.11"
ansi_term = "0.12.1"
arboard = {version = "1.1.0", optional = true}
async-recursion = "0.3.1"
async-trait = "0.1.40"
base64 = "0.13.0"
bigdecimal = {version = "0.2.0", features = ["serde"]}
byte-unit = "4.0.9"
bytes = "0.5.6"
calamine = "0.16.1"
chrono = {version = "0.4.15", features = ["serde"]}
chrono-tz = "0.5.3"
clap = "2.33.3"
codespan-reporting = "0.11.0"
csv = "1.1.3"
ctrlc = {version = "3.1.6", optional = true}
derive-new = "0.5.8"
directories = {version = "3.0.1", optional = true}
dirs = {version = "3.0.1", optional = true}
dtparse = "1.2.0"
dunce = "1.0.1"
eml-parser = "0.1.0"
encoding_rs = "0.8.24"
filesize = "0.2.0"
fs_extra = "1.2.0"
futures = {version = "0.3.5", features = ["compat", "io-compat"]}
futures-util = "0.3.8"
futures_codec = "0.4.1"
getset = "0.1.1"
git2 = {version = "0.13.11", default_features = false, optional = true}
glob = "0.3.0"
heim = {version = "0.1.0-rc.1", optional = true}
htmlescape = "0.3.1"
ical = "0.7.0"
ichwh = {version = "0.3.4", optional = true}
indexmap = {version = "1.6.0", features = ["serde-1"]}
itertools = "0.10.0"
lazy_static = "1.*"
log = "0.4.11"
meval = "0.2.0"
num-bigint = {version = "0.3.0", features = ["serde"]}
num-format = {version = "0.4.0", features = ["with-num-bigint"]}
num-traits = "0.2.12"
parking_lot = "0.11.0"
pin-utils = "0.1.0"
pretty-hex = "0.2.0"
ptree = {version = "0.3.0", optional = true}
query_interface = "0.3.5"
quick-xml = "0.20.0"
rand = "0.7.3"
rayon = "1.4.0"
regex = "1.3.9"
roxmltree = "0.14.0"
rust-embed = "5.8.0"
rustyline = {version = "6.3.0", optional = true}
serde = {version = "1.0.115", features = ["derive"]}
serde_bytes = "0.11.5"
serde_ini = "0.2.0"
serde_json = "1.0.57"
serde_urlencoded = "0.7.0"
serde_yaml = "0.8.13"
sha2 = "0.9.1"
shellexpand = "2.0.0"
strip-ansi-escapes = "0.1.0"
sxd-document = "0.3.2"
sxd-xpath = "0.4.2"
tempfile = "3.1.0"
term = {version = "0.6.1", optional = true}
term_size = "0.3.2"
termcolor = "1.1.0"
titlecase = "1.0"
toml = "0.5.6"
trash = {version = "1.2.0", optional = true}
unicode-segmentation = "1.6.0"
uom = {version = "0.30.0", features = ["f64", "try-from"]}
url = "2.1.1"
uuid_crate = {package = "uuid", version = "0.8.1", features = ["v4"], optional = true}
which = {version = "4.0.2", optional = true}
zip = {version = "0.5.7", optional = true}
[target.'cfg(unix)'.dependencies]
umask = "1.0.0"
users = "0.10.0"
# TODO this will be possible with new dependency resolver
# (currently on nightly behind -Zfeatures=itarget):
# https://github.com/rust-lang/cargo/issues/7914
#[target.'cfg(not(windows))'.dependencies]
#num-format = {version = "0.4", features = ["with-system-locale"]}
[dependencies.rusqlite]
features = ["bundled", "blob"]
optional = true
version = "0.24.2"
[build-dependencies]
shadow-rs = "0.5"
[dev-dependencies]
quickcheck = "0.9.2"
quickcheck_macros = "0.9.1"
[features]
clipboard-cli = ["arboard"]
rich-benchmark = ["heim"]
rustyline-support = ["rustyline"]
stable = []
trash-support = ["trash"]

Binary file not shown.

View File

@ -0,0 +1,3 @@
fn main() -> shadow_rs::SdResult<()> {
shadow_rs::new()
}

View File

@ -7,7 +7,7 @@ mod to_delimited_data;
pub(crate) mod ansi;
pub(crate) mod append;
pub(crate) mod args;
pub(crate) mod autoenv;
pub mod autoenv;
pub(crate) mod autoenv_trust;
pub(crate) mod autoenv_untrust;
pub(crate) mod autoview;
@ -20,7 +20,7 @@ pub(crate) mod chart;
pub(crate) mod classified;
#[cfg(feature = "clipboard-cli")]
pub(crate) mod clip;
pub(crate) mod command;
pub mod command;
pub(crate) mod compact;
pub(crate) mod config;
pub(crate) mod constants;
@ -30,7 +30,7 @@ pub(crate) mod date;
pub(crate) mod debug;
pub(crate) mod def;
pub(crate) mod default;
pub(crate) mod default_context;
pub mod default_context;
pub(crate) mod describe;
pub(crate) mod do_;
pub(crate) mod drop;

Some files were not shown because too many files have changed in this diff Show More