Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Break up interdependencies of command crates #9429

Merged
merged 4 commits into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ nu-cli = { path = "./crates/nu-cli", version = "0.81.1" }
nu-color-config = { path = "./crates/nu-color-config", version = "0.81.1" }
nu-cmd-lang = { path = "./crates/nu-cmd-lang", version = "0.81.1" }
nu-cmd-dataframe = { path = "./crates/nu-cmd-dataframe", version = "0.81.1", optional = true }
nu-cmd-extra = { path = "./crates/nu-cmd-extra", version = "0.81.1", optional = true }
nu-command = { path = "./crates/nu-command", version = "0.81.1" }
nu-engine = { path = "./crates/nu-engine", version = "0.81.1" }
nu-explore = { path = "./crates/nu-explore", version = "0.81.1" }
Expand Down Expand Up @@ -112,6 +113,7 @@ plugin = [
default = ["plugin", "which-support", "trash-support", "sqlite"]
stable = ["default"]
wasi = ["nu-cmd-lang/wasi"]
# NOTE: individual features are also passed to `nu-cmd-lang` that uses them to generate the feature matrix in the `version` command

# Enable to statically link OpenSSL; otherwise the system version will be used. Not enabled by default because it takes a while to build
static-link-openssl = ["dep:openssl", "nu-cmd-lang/static-link-openssl"]
Expand All @@ -121,10 +123,10 @@ which-support = ["nu-command/which-support", "nu-cmd-lang/which-support"]
trash-support = ["nu-command/trash-support", "nu-cmd-lang/trash-support"]

# Extra feature for nushell
extra = ["nu-command/extra", "nu-cmd-lang/extra"]
extra = ["dep:nu-cmd-extra", "nu-cmd-lang/extra"]

# Dataframe feature for nushell
dataframe = ["nu-command/dataframe", "nu-cmd-lang/dataframe"]
dataframe = ["dep:nu-cmd-dataframe", "nu-cmd-lang/dataframe"]

# SQLite commands for nushell
sqlite = ["nu-command/sqlite", "nu-cmd-lang/sqlite"]
Expand Down
1 change: 1 addition & 0 deletions crates/nu-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ version = "0.81.1"
bench = false

[dev-dependencies]
nu-cmd-lang = { path = "../nu-cmd-lang", version = "0.81.1" }
nu-test-support = { path = "../nu-test-support", version = "0.81.1" }
rstest = { version = "0.17.0", default-features = false }

Expand Down
2 changes: 1 addition & 1 deletion crates/nu-cli/src/commands/default_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub fn add_cli_context(mut engine_state: EngineState) -> EngineState {
};

if let Err(err) = engine_state.merge_delta(delta) {
eprintln!("Error creating default context: {err:?}");
eprintln!("Error creating CLI command context: {err:?}");
}

engine_state
Expand Down
3 changes: 2 additions & 1 deletion crates/nu-cli/src/completions/completer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,8 @@ mod completer_tests {

#[test]
fn test_completion_helper() {
let mut engine_state = nu_command::create_default_context();
let mut engine_state =
nu_command::add_shell_command_context(nu_cmd_lang::create_default_context());

// Custom additions
let delta = {
Expand Down
5 changes: 4 additions & 1 deletion crates/nu-cli/tests/support/completions_helpers.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::path::PathBuf;

use nu_command::create_default_context;
use nu_engine::eval_block;
use nu_parser::parse;
use nu_protocol::{
Expand All @@ -11,6 +10,10 @@ use nu_test_support::fs;
use reedline::Suggestion;
const SEP: char = std::path::MAIN_SEPARATOR;

fn create_default_context() -> EngineState {
nu_command::add_shell_command_context(nu_cmd_lang::create_default_context())
}

// creates a new engine with the current path into the completions fixtures folder
pub fn new_engine() -> (PathBuf, String, EngineState, Stack) {
// Target folder inside assets
Expand Down
2 changes: 1 addition & 1 deletion crates/nu-cmd-dataframe/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ version = "0.81.1"
bench = false

[dependencies]
nu-cmd-lang = { path = "../nu-cmd-lang", version = "0.81.1" }
nu-engine = { path = "../nu-engine", version = "0.81.1" }
nu-parser = { path = "../nu-parser", version = "0.81.1" }
nu-protocol = { path = "../nu-protocol", version = "0.81.1" }
Expand Down Expand Up @@ -66,4 +65,5 @@ dataframe = ["default"]
default = ["num", "polars", "sqlparser"]

[dev-dependencies]
nu-cmd-lang = { path = "../nu-cmd-lang", version = "0.81.1" }
nu-test-support = { path = "../nu-test-support", version = "0.81.1" }
23 changes: 17 additions & 6 deletions crates/nu-cmd-dataframe/src/dataframe/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,24 @@ pub use expressions::add_expressions;
pub use lazy::add_lazy_decls;
pub use series::add_series_decls;

use nu_protocol::engine::StateWorkingSet;
use nu_protocol::engine::{EngineState, StateWorkingSet};

pub fn add_dataframe_decls(working_set: &mut StateWorkingSet) {
add_series_decls(working_set);
add_eager_decls(working_set);
add_expressions(working_set);
add_lazy_decls(working_set);
pub fn add_dataframe_context(mut engine_state: EngineState) -> EngineState {
let delta = {
let mut working_set = StateWorkingSet::new(&engine_state);
add_series_decls(&mut working_set);
add_eager_decls(&mut working_set);
add_expressions(&mut working_set);
add_lazy_decls(&mut working_set);

working_set.render()
};

if let Err(err) = engine_state.merge_delta(delta) {
eprintln!("Error creating dataframe command context: {err:?}");
}

engine_state
}

#[cfg(test)]
Expand Down
2 changes: 1 addition & 1 deletion crates/nu-cmd-extra/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ version = "0.81.1"
bench = false

[dependencies]
nu-cmd-lang = { path = "../nu-cmd-lang", version = "0.81.1" }
nu-engine = { path = "../nu-engine", version = "0.81.1" }
nu-parser = { path = "../nu-parser", version = "0.81.1" }
nu-protocol = { path = "../nu-protocol", version = "0.81.1" }
Expand All @@ -27,4 +26,5 @@ extra = ["default"]
default = []

[dev-dependencies]
nu-cmd-lang = { path = "../nu-cmd-lang", version = "0.81.1" }
nu-test-support = { path = "../nu-test-support", version = "0.81.1" }
39 changes: 25 additions & 14 deletions crates/nu-cmd-extra/src/extra/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
mod bits;

use nu_protocol::engine::StateWorkingSet;
use nu_protocol::engine::{EngineState, StateWorkingSet};

pub fn add_extra_decls(working_set: &mut StateWorkingSet) {
macro_rules! bind_command {
pub fn add_extra_command_context(mut engine_state: EngineState) -> EngineState {
let delta = {
let mut working_set = StateWorkingSet::new(&engine_state);

macro_rules! bind_command {
( $command:expr ) => {
working_set.add_decl(Box::new($command));
};
Expand All @@ -12,15 +15,23 @@ pub fn add_extra_decls(working_set: &mut StateWorkingSet) {
};
}

bind_command!(
bits::bits_::Bits,
bits::and::BitsAnd,
bits::not::BitsNot,
bits::or::BitsOr,
bits::xor::BitsXor,
bits::rotate_left::BitsRol,
bits::rotate_right::BitsRor,
bits::shift_left::BitsShl,
bits::shift_right::BitsShr
);
bind_command!(
bits::bits_::Bits,
bits::and::BitsAnd,
bits::not::BitsNot,
bits::or::BitsOr,
bits::xor::BitsXor,
bits::rotate_left::BitsRol,
bits::rotate_right::BitsRor,
bits::shift_left::BitsShl,
bits::shift_right::BitsShr
);
working_set.render()
};

if let Err(err) = engine_state.merge_delta(delta) {
eprintln!("Error creating extra command context: {err:?}");
}

engine_state
}
12 changes: 0 additions & 12 deletions crates/nu-cmd-lang/src/core_commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@ mod export_module;
mod export_use;
mod extern_;
mod for_;
pub mod help;
pub mod help_aliases;
pub mod help_commands;
pub mod help_externs;
pub mod help_modules;
mod help_operators;
mod hide;
mod hide_env;
mod if_;
Expand Down Expand Up @@ -61,12 +55,6 @@ pub use export_module::ExportModule;
pub use export_use::ExportUse;
pub use extern_::Extern;
pub use for_::For;
pub use help::Help;
pub use help_aliases::HelpAliases;
pub use help_commands::HelpCommands;
pub use help_externs::HelpExterns;
pub use help_modules::HelpModules;
pub use help_operators::HelpOperators;
pub use hide::Hide;
pub use hide_env::HideEnv;
pub use if_::If;
Expand Down
6 changes: 0 additions & 6 deletions crates/nu-cmd-lang/src/default_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,6 @@ pub fn create_default_context() -> EngineState {
ExportModule,
Extern,
For,
Help,
HelpAliases,
HelpCommands,
HelpModules,
HelpExterns,
HelpOperators,
Hide,
HideEnv,
If,
Expand Down
11 changes: 3 additions & 8 deletions crates/nu-command/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ version = "0.81.1"
bench = false

[dependencies]
nu-cmd-lang = { path = "../nu-cmd-lang", version = "0.81.1" }
nu-cmd-dataframe = { path = "../nu-cmd-dataframe", version = "0.81.1", optional = true }
nu-cmd-extra = { path = "../nu-cmd-extra", version = "0.81.1", optional = true }
nu-color-config = { path = "../nu-color-config", version = "0.81.1" }
nu-engine = { path = "../nu-engine", version = "0.81.1" }
nu-glob = { path = "../nu-glob", version = "0.81.1" }
Expand Down Expand Up @@ -117,17 +114,15 @@ features = ["Win32_Foundation", "Win32_Storage_FileSystem", "Win32_System_System
version = "0.48"

[features]
dataframe = ["dep:nu-cmd-dataframe"]
extra = ["dep:nu-cmd-extra"]
plugin = ["nu-parser/plugin"]
sqlite = [
"rusqlite",
] # TODO: given that rusqlite is included in reedline, should we just always include it?
sqlite = ["rusqlite"]
trash-support = ["trash"]
which-support = ["which"]

[dev-dependencies]
nu-cmd-lang = { path = "../nu-cmd-lang", version = "0.81.1" }
nu-test-support = { path = "../nu-test-support", version = "0.81.1" }

dirs-next = "2.0"
mockito = "1.0"
quickcheck = "1.0"
Expand Down
31 changes: 15 additions & 16 deletions crates/nu-command/src/default_context.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
use nu_protocol::engine::{EngineState, StateWorkingSet};

use crate::*;
#[cfg(feature = "dataframe")]
use nu_cmd_dataframe::*;

#[cfg(feature = "extra")]
use nu_cmd_extra::*;

pub fn create_default_context() -> EngineState {
let mut engine_state = nu_cmd_lang::create_default_context();

use crate::{
help::{HelpAliases, HelpCommands, HelpExterns, HelpModules, HelpOperators},
*,
};
pub fn add_shell_command_context(mut engine_state: EngineState) -> EngineState {
let delta = {
let mut working_set = StateWorkingSet::new(&engine_state);

Expand All @@ -24,12 +19,6 @@ pub fn create_default_context() -> EngineState {
// them only accessible if the correct input value category is used with the
// declaration

#[cfg(feature = "extra")]
add_extra_decls(&mut working_set);

#[cfg(feature = "dataframe")]
add_dataframe_decls(&mut working_set);

// Database-related
// Adds all related commands to query databases
#[cfg(feature = "sqlite")]
Expand Down Expand Up @@ -138,6 +127,16 @@ pub fn create_default_context() -> EngineState {
Sys,
};

// Help
bind_command! {
Help,
HelpAliases,
HelpExterns,
HelpCommands,
HelpModules,
HelpOperators,
};

// Debug
bind_command! {
Ast,
Expand Down
2 changes: 1 addition & 1 deletion crates/nu-command/src/filters/find.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::help::highlight_search_string;
use itertools::Itertools;
use nu_cmd_lang::help::highlight_search_string;

use fancy_regex::Regex;
use nu_ansi_term::Style;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::help_aliases::help_aliases;
use crate::help_commands::help_commands;
use crate::help_modules::help_modules;
use crate::help::help_aliases;
use crate::help::help_commands;
use crate::help::help_modules;
use fancy_regex::Regex;
use nu_ansi_term::Style;
use nu_engine::CallExt;
Expand Down
18 changes: 18 additions & 0 deletions crates/nu-command/src/help/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
mod help_;
mod help_aliases;
mod help_commands;
mod help_externs;
mod help_modules;
mod help_operators;

pub use help_::Help;
pub use help_aliases::HelpAliases;
pub use help_commands::HelpCommands;
pub use help_externs::HelpExterns;
pub use help_modules::HelpModules;
pub use help_operators::HelpOperators;

pub(crate) use help_::{highlight_search_in_table, highlight_search_string};
pub(crate) use help_aliases::help_aliases;
pub(crate) use help_commands::help_commands;
pub(crate) use help_modules::help_modules;
2 changes: 2 additions & 0 deletions crates/nu-command/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ mod filters;
mod formats;
mod generators;
mod hash;
mod help;
pub mod hook;
mod input_handler;
mod math;
Expand Down Expand Up @@ -45,6 +46,7 @@ pub use filters::*;
pub use formats::*;
pub use generators::*;
pub use hash::*;
pub use help::*;
pub use hook::*;
pub use math::*;
pub use misc::*;
Expand Down