diff --git a/Cargo.lock b/Cargo.lock index 59efcb02b..1cd90aa02 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2671,6 +2671,7 @@ dependencies = [ "nix", "nu-ansi-term", "nu-cli", + "nu-cmd-base", "nu-cmd-dataframe", "nu-cmd-extra", "nu-cmd-lang", @@ -2725,6 +2726,7 @@ dependencies = [ "log", "miette", "nu-ansi-term", + "nu-cmd-base", "nu-cmd-lang", "nu-color-config", "nu-command", @@ -2746,6 +2748,8 @@ dependencies = [ name = "nu-cmd-base" version = "0.81.1" dependencies = [ + "nu-engine", + "nu-path", "nu-protocol", ] @@ -2771,11 +2775,13 @@ dependencies = [ name = "nu-cmd-extra" version = "0.81.1" dependencies = [ + "nu-cmd-base", "nu-cmd-lang", "nu-engine", "nu-parser", "nu-protocol", "nu-test-support", + "nu-utils", "num-traits", ] diff --git a/Cargo.toml b/Cargo.toml index 91463a0f8..82e91785d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -48,6 +48,7 @@ members = [ [dependencies] nu-cli = { path = "./crates/nu-cli", version = "0.81.1" } nu-color-config = { path = "./crates/nu-color-config", version = "0.81.1" } +nu-cmd-base = { path = "./crates/nu-cmd-base", 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 } diff --git a/crates/nu-cli/Cargo.toml b/crates/nu-cli/Cargo.toml index 8c00e2dd8..f4ee497fb 100644 --- a/crates/nu-cli/Cargo.toml +++ b/crates/nu-cli/Cargo.toml @@ -16,6 +16,7 @@ nu-test-support = { path = "../nu-test-support", version = "0.81.1" } rstest = { version = "0.17.0", default-features = false } [dependencies] +nu-cmd-base = { path = "../nu-cmd-base", version = "0.81.1" } nu-command = { path = "../nu-command", version = "0.81.1" } nu-engine = { path = "../nu-engine", version = "0.81.1" } nu-path = { path = "../nu-path", version = "0.81.1" } diff --git a/crates/nu-cli/src/lib.rs b/crates/nu-cli/src/lib.rs index 368802a47..641319bdf 100644 --- a/crates/nu-cli/src/lib.rs +++ b/crates/nu-cli/src/lib.rs @@ -20,7 +20,7 @@ pub use config_files::eval_config_contents; pub use eval_cmds::evaluate_commands; pub use eval_file::evaluate_file; pub use menus::{DescriptionMenu, NuHelpCompleter}; -pub use nu_command::util::get_init_cwd; +pub use nu_cmd_base::util::get_init_cwd; pub use nu_highlight::NuHighlight; pub use print::Print; pub use prompt::NushellPrompt; diff --git a/crates/nu-cli/src/repl.rs b/crates/nu-cli/src/repl.rs index b12e89b48..6faf29772 100644 --- a/crates/nu-cli/src/repl.rs +++ b/crates/nu-cli/src/repl.rs @@ -8,9 +8,9 @@ use crate::{ use crossterm::cursor::SetCursorStyle; use log::{trace, warn}; use miette::{IntoDiagnostic, Result}; +use nu_cmd_base::util::get_guaranteed_cwd; use nu_color_config::StyleComputer; use nu_command::hook::eval_hook; -use nu_command::util::get_guaranteed_cwd; use nu_engine::convert_env_values; use nu_parser::{lex, parse, trim_quotes_str}; use nu_protocol::{ diff --git a/crates/nu-cmd-base/Cargo.toml b/crates/nu-cmd-base/Cargo.toml index b7e0280c0..f169ee53e 100644 --- a/crates/nu-cmd-base/Cargo.toml +++ b/crates/nu-cmd-base/Cargo.toml @@ -10,4 +10,6 @@ version = "0.81.1" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +nu-engine = { path = "../nu-engine", version = "0.81.1" } +nu-path = { path = "../nu-path", version = "0.81.1" } nu-protocol = { version = "0.81.1", path = "../nu-protocol" } diff --git a/crates/nu-cmd-base/src/lib.rs b/crates/nu-cmd-base/src/lib.rs index 132fd33de..a58a12401 100644 --- a/crates/nu-cmd-base/src/lib.rs +++ b/crates/nu-cmd-base/src/lib.rs @@ -1 +1,2 @@ pub mod input_handler; +pub mod util; diff --git a/crates/nu-command/src/util.rs b/crates/nu-cmd-base/src/util.rs similarity index 100% rename from crates/nu-command/src/util.rs rename to crates/nu-cmd-base/src/util.rs diff --git a/crates/nu-cmd-extra/Cargo.toml b/crates/nu-cmd-extra/Cargo.toml index 6d1dd3d91..319e8f950 100644 --- a/crates/nu-cmd-extra/Cargo.toml +++ b/crates/nu-cmd-extra/Cargo.toml @@ -16,6 +16,8 @@ bench = false 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" } +nu-cmd-base = { path = "../nu-cmd-base", version = "0.81.1" } +nu-utils = { path = "../nu-utils", version = "0.81.1" } # Potential dependencies for extras num-traits = "0.2" diff --git a/crates/nu-command/src/bytes/add.rs b/crates/nu-cmd-extra/src/extra/bytes/add.rs similarity index 100% rename from crates/nu-command/src/bytes/add.rs rename to crates/nu-cmd-extra/src/extra/bytes/add.rs diff --git a/crates/nu-command/src/bytes/at.rs b/crates/nu-cmd-extra/src/extra/bytes/at.rs similarity index 99% rename from crates/nu-command/src/bytes/at.rs rename to crates/nu-cmd-extra/src/extra/bytes/at.rs index e0ca09e7f..c8c6c3b39 100644 --- a/crates/nu-command/src/bytes/at.rs +++ b/crates/nu-cmd-extra/src/extra/bytes/at.rs @@ -1,5 +1,5 @@ -use crate::util; use nu_cmd_base::input_handler::{operate, CmdArgument}; +use nu_cmd_base::util; use nu_engine::CallExt; use nu_protocol::{ ast::{Call, CellPath}, diff --git a/crates/nu-command/src/bytes/build_.rs b/crates/nu-cmd-extra/src/extra/bytes/build_.rs similarity index 100% rename from crates/nu-command/src/bytes/build_.rs rename to crates/nu-cmd-extra/src/extra/bytes/build_.rs diff --git a/crates/nu-command/src/bytes/bytes_.rs b/crates/nu-cmd-extra/src/extra/bytes/bytes_.rs similarity index 100% rename from crates/nu-command/src/bytes/bytes_.rs rename to crates/nu-cmd-extra/src/extra/bytes/bytes_.rs diff --git a/crates/nu-command/src/bytes/collect.rs b/crates/nu-cmd-extra/src/extra/bytes/collect.rs similarity index 100% rename from crates/nu-command/src/bytes/collect.rs rename to crates/nu-cmd-extra/src/extra/bytes/collect.rs diff --git a/crates/nu-command/src/bytes/ends_with.rs b/crates/nu-cmd-extra/src/extra/bytes/ends_with.rs similarity index 100% rename from crates/nu-command/src/bytes/ends_with.rs rename to crates/nu-cmd-extra/src/extra/bytes/ends_with.rs diff --git a/crates/nu-command/src/bytes/index_of.rs b/crates/nu-cmd-extra/src/extra/bytes/index_of.rs similarity index 100% rename from crates/nu-command/src/bytes/index_of.rs rename to crates/nu-cmd-extra/src/extra/bytes/index_of.rs diff --git a/crates/nu-command/src/bytes/length.rs b/crates/nu-cmd-extra/src/extra/bytes/length.rs similarity index 100% rename from crates/nu-command/src/bytes/length.rs rename to crates/nu-cmd-extra/src/extra/bytes/length.rs diff --git a/crates/nu-command/src/bytes/mod.rs b/crates/nu-cmd-extra/src/extra/bytes/mod.rs similarity index 100% rename from crates/nu-command/src/bytes/mod.rs rename to crates/nu-cmd-extra/src/extra/bytes/mod.rs diff --git a/crates/nu-command/src/bytes/remove.rs b/crates/nu-cmd-extra/src/extra/bytes/remove.rs similarity index 100% rename from crates/nu-command/src/bytes/remove.rs rename to crates/nu-cmd-extra/src/extra/bytes/remove.rs diff --git a/crates/nu-command/src/bytes/replace.rs b/crates/nu-cmd-extra/src/extra/bytes/replace.rs similarity index 100% rename from crates/nu-command/src/bytes/replace.rs rename to crates/nu-cmd-extra/src/extra/bytes/replace.rs diff --git a/crates/nu-command/src/bytes/reverse.rs b/crates/nu-cmd-extra/src/extra/bytes/reverse.rs similarity index 100% rename from crates/nu-command/src/bytes/reverse.rs rename to crates/nu-cmd-extra/src/extra/bytes/reverse.rs diff --git a/crates/nu-command/src/bytes/starts_with.rs b/crates/nu-cmd-extra/src/extra/bytes/starts_with.rs similarity index 100% rename from crates/nu-command/src/bytes/starts_with.rs rename to crates/nu-cmd-extra/src/extra/bytes/starts_with.rs diff --git a/crates/nu-cmd-extra/src/extra/mod.rs b/crates/nu-cmd-extra/src/extra/mod.rs index 39ce5d6d0..0c3897938 100644 --- a/crates/nu-cmd-extra/src/extra/mod.rs +++ b/crates/nu-cmd-extra/src/extra/mod.rs @@ -1,4 +1,18 @@ mod bits; +mod bytes; + +pub use bytes::Bytes; +pub use bytes::BytesAdd; +pub use bytes::BytesAt; +pub use bytes::BytesBuild; +pub use bytes::BytesCollect; +pub use bytes::BytesEndsWith; +pub use bytes::BytesIndexOf; +pub use bytes::BytesLen; +pub use bytes::BytesRemove; +pub use bytes::BytesReplace; +pub use bytes::BytesReverse; +pub use bytes::BytesStartsWith; use nu_protocol::engine::{EngineState, StateWorkingSet}; @@ -15,7 +29,7 @@ pub fn add_extra_command_context(mut engine_state: EngineState) -> EngineState { }; } - bind_command!( + bind_command! { bits::bits_::Bits, bits::and::BitsAnd, bits::not::BitsNot, @@ -25,7 +39,24 @@ pub fn add_extra_command_context(mut engine_state: EngineState) -> EngineState { bits::rotate_right::BitsRor, bits::shift_left::BitsShl, bits::shift_right::BitsShr - ); + } + + // Bytes + bind_command! { + Bytes, + BytesLen, + BytesStartsWith, + BytesEndsWith, + BytesReverse, + BytesReplace, + BytesAdd, + BytesAt, + BytesIndexOf, + BytesCollect, + BytesRemove, + BytesBuild + } + working_set.render() }; diff --git a/crates/nu-command/tests/commands/bytes/mod.rs b/crates/nu-cmd-extra/tests/commands/bytes/mod.rs similarity index 100% rename from crates/nu-command/tests/commands/bytes/mod.rs rename to crates/nu-cmd-extra/tests/commands/bytes/mod.rs diff --git a/crates/nu-command/tests/commands/bytes/starts_with.rs b/crates/nu-cmd-extra/tests/commands/bytes/starts_with.rs similarity index 100% rename from crates/nu-command/tests/commands/bytes/starts_with.rs rename to crates/nu-cmd-extra/tests/commands/bytes/starts_with.rs diff --git a/crates/nu-cmd-extra/tests/commands/mod.rs b/crates/nu-cmd-extra/tests/commands/mod.rs new file mode 100644 index 000000000..9195fb60d --- /dev/null +++ b/crates/nu-cmd-extra/tests/commands/mod.rs @@ -0,0 +1,2 @@ +#[cfg(feature = "extra")] +mod bytes; diff --git a/crates/nu-cmd-extra/tests/main.rs b/crates/nu-cmd-extra/tests/main.rs new file mode 100644 index 000000000..f3d44688d --- /dev/null +++ b/crates/nu-cmd-extra/tests/main.rs @@ -0,0 +1 @@ +mod commands; diff --git a/crates/nu-command/Cargo.toml b/crates/nu-command/Cargo.toml index 7f9b7f0d1..059f09ed6 100644 --- a/crates/nu-command/Cargo.toml +++ b/crates/nu-command/Cargo.toml @@ -13,6 +13,7 @@ version = "0.81.1" bench = false [dependencies] +nu-cmd-base = { path = "../nu-cmd-base", version = "0.81.1" } 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" } @@ -95,7 +96,6 @@ url = "2.2" uuid = { version = "1.3", features = ["v4"] } wax = { version = "0.5" } which = { version = "4.4", optional = true } -nu-cmd-base = { version = "0.81.1", path = "../nu-cmd-base" } [target.'cfg(windows)'.dependencies] winreg = "0.50" diff --git a/crates/nu-command/src/default_context.rs b/crates/nu-command/src/default_context.rs index 95af0f6bb..6937ac121 100644 --- a/crates/nu-command/src/default_context.rs +++ b/crates/nu-command/src/default_context.rs @@ -211,22 +211,6 @@ pub fn add_shell_command_context(mut engine_state: EngineState) -> EngineState { StrUpcase }; - // Bytes - bind_command! { - Bytes, - BytesLen, - BytesStartsWith, - BytesEndsWith, - BytesReverse, - BytesReplace, - BytesAdd, - BytesAt, - BytesIndexOf, - BytesCollect, - BytesRemove, - BytesBuild, - } - // FileSystem bind_command! { Cd, diff --git a/crates/nu-command/src/hook.rs b/crates/nu-command/src/hook.rs index 40b9a77a0..3dc299001 100644 --- a/crates/nu-command/src/hook.rs +++ b/crates/nu-command/src/hook.rs @@ -1,5 +1,5 @@ -use crate::util::get_guaranteed_cwd; use miette::Result; +use nu_cmd_base::util::get_guaranteed_cwd; use nu_engine::{eval_block, eval_block_with_early_return}; use nu_parser::parse; use nu_protocol::ast::PathMember; diff --git a/crates/nu-command/src/lib.rs b/crates/nu-command/src/lib.rs index f825b7b64..1d9b2727c 100644 --- a/crates/nu-command/src/lib.rs +++ b/crates/nu-command/src/lib.rs @@ -1,4 +1,3 @@ -mod bytes; mod charting; mod conversions; mod date; @@ -26,10 +25,8 @@ mod shells; mod sort_utils; mod strings; mod system; -pub mod util; mod viewers; -pub use bytes::*; pub use charting::*; pub use conversions::*; pub use date::*; @@ -57,7 +54,6 @@ pub use shells::*; pub use sort_utils::*; pub use strings::*; pub use system::*; -pub use util::*; pub use viewers::*; #[cfg(feature = "sqlite")] diff --git a/crates/nu-command/src/strings/str_/index_of.rs b/crates/nu-command/src/strings/str_/index_of.rs index 678f9a803..86d0d3bac 100644 --- a/crates/nu-command/src/strings/str_/index_of.rs +++ b/crates/nu-command/src/strings/str_/index_of.rs @@ -1,5 +1,6 @@ -use crate::{grapheme_flags, util}; +use crate::grapheme_flags; use nu_cmd_base::input_handler::{operate, CmdArgument}; +use nu_cmd_base::util; use nu_engine::CallExt; use nu_protocol::{ ast::{Call, CellPath}, diff --git a/crates/nu-command/src/strings/str_/substring.rs b/crates/nu-command/src/strings/str_/substring.rs index 180a690d9..c94b0edd5 100644 --- a/crates/nu-command/src/strings/str_/substring.rs +++ b/crates/nu-command/src/strings/str_/substring.rs @@ -1,5 +1,6 @@ -use crate::{grapheme_flags, util}; +use crate::grapheme_flags; use nu_cmd_base::input_handler::{operate, CmdArgument}; +use nu_cmd_base::util; use nu_engine::CallExt; use nu_protocol::ast::Call; use nu_protocol::ast::CellPath; diff --git a/crates/nu-command/tests/commands/mod.rs b/crates/nu-command/tests/commands/mod.rs index c5ce4c814..841de7172 100644 --- a/crates/nu-command/tests/commands/mod.rs +++ b/crates/nu-command/tests/commands/mod.rs @@ -4,7 +4,6 @@ mod any; mod append; mod assignment; mod break_; -mod bytes; mod cal; mod cd; mod compact; diff --git a/src/main.rs b/src/main.rs index a6cc443ea..9ac51fd68 100644 --- a/src/main.rs +++ b/src/main.rs @@ -23,7 +23,7 @@ use command::gather_commandline_args; use log::Level; use miette::Result; use nu_cli::gather_parent_env_vars; -use nu_command::get_init_cwd; +use nu_cmd_base::util::get_init_cwd; use nu_protocol::{engine::EngineState, report_error_new, Value}; use nu_protocol::{util::BufferedReader, PipelineData, RawStream}; use nu_std::load_standard_library;