diff --git a/crates/nu-cmd-extra/src/extra/bits/and.rs b/crates/nu-cmd-extra/src/extra/bits/and.rs index b7514959e2..e63b6f23e6 100644 --- a/crates/nu-cmd-extra/src/extra/bits/and.rs +++ b/crates/nu-cmd-extra/src/extra/bits/and.rs @@ -6,9 +6,9 @@ use nu_protocol::{ }; #[derive(Clone)] -pub struct SubCommand; +pub struct BitsAnd; -impl Command for SubCommand { +impl Command for BitsAnd { fn name(&self) -> &str { "bits and" } @@ -99,6 +99,6 @@ mod test { fn test_examples() { use crate::test_examples; - test_examples(SubCommand {}) + test_examples(BitsAnd {}) } } diff --git a/crates/nu-cmd-extra/src/extra/bits/mod.rs b/crates/nu-cmd-extra/src/extra/bits/mod.rs index 9bc6775019..99cbf5f839 100644 --- a/crates/nu-cmd-extra/src/extra/bits/mod.rs +++ b/crates/nu-cmd-extra/src/extra/bits/mod.rs @@ -1,50 +1,15 @@ -mod and; -mod bits_; -mod not; -mod or; -mod rotate_left; -mod rotate_right; -mod shift_left; -mod shift_right; -mod xor; +pub(crate) mod and; +pub(crate) mod bits_; +pub(crate) mod not; +pub(crate) mod or; +pub(crate) mod rotate_left; +pub(crate) mod rotate_right; +pub(crate) mod shift_left; +pub(crate) mod shift_right; +pub(crate) mod xor; -use nu_protocol::engine::StateWorkingSet; use nu_protocol::Spanned; -pub use and::SubCommand as BitsAnd; -pub use bits_::Bits; -pub use not::SubCommand as BitsNot; -pub use or::SubCommand as BitsOr; -pub use rotate_left::SubCommand as BitsRotateLeft; -pub use rotate_right::SubCommand as BitsRotateRight; -pub use shift_left::SubCommand as BitsShiftLeft; -pub use shift_right::SubCommand as BitsShiftRight; -pub use xor::SubCommand as BitsXor; - -pub fn add_bits_decls(working_set: &mut StateWorkingSet) { - macro_rules! bind_command { - ( $command:expr ) => { - working_set.add_decl(Box::new($command)); - }; - ( $( $command:expr ),* ) => { - $( working_set.add_decl(Box::new($command)); )* - }; - } - - // Dataframe commands - bind_command!( - Bits, - BitsAnd, - BitsNot, - BitsOr, - BitsXor, - BitsRotateLeft, - BitsRotateRight, - BitsShiftLeft, - BitsShiftRight - ); -} - #[derive(Clone, Copy)] enum NumberBytes { One, diff --git a/crates/nu-cmd-extra/src/extra/bits/not.rs b/crates/nu-cmd-extra/src/extra/bits/not.rs index 1b5b2475d1..4948a1c4a1 100644 --- a/crates/nu-cmd-extra/src/extra/bits/not.rs +++ b/crates/nu-cmd-extra/src/extra/bits/not.rs @@ -7,9 +7,9 @@ use nu_protocol::{ }; #[derive(Clone)] -pub struct SubCommand; +pub struct BitsNot; -impl Command for SubCommand { +impl Command for BitsNot { fn name(&self) -> &str { "bits not" } @@ -169,6 +169,6 @@ mod test { fn test_examples() { use crate::test_examples; - test_examples(SubCommand {}) + test_examples(BitsNot {}) } } diff --git a/crates/nu-cmd-extra/src/extra/bits/or.rs b/crates/nu-cmd-extra/src/extra/bits/or.rs index 47d8f69d44..1c3c7243de 100644 --- a/crates/nu-cmd-extra/src/extra/bits/or.rs +++ b/crates/nu-cmd-extra/src/extra/bits/or.rs @@ -6,9 +6,9 @@ use nu_protocol::{ }; #[derive(Clone)] -pub struct SubCommand; +pub struct BitsOr; -impl Command for SubCommand { +impl Command for BitsOr { fn name(&self) -> &str { "bits or" } @@ -99,6 +99,6 @@ mod test { fn test_examples() { use crate::test_examples; - test_examples(SubCommand {}) + test_examples(BitsOr {}) } } diff --git a/crates/nu-cmd-extra/src/extra/bits/rotate_left.rs b/crates/nu-cmd-extra/src/extra/bits/rotate_left.rs index caf6f1177e..d299dd6dcc 100644 --- a/crates/nu-cmd-extra/src/extra/bits/rotate_left.rs +++ b/crates/nu-cmd-extra/src/extra/bits/rotate_left.rs @@ -9,9 +9,9 @@ use num_traits::int::PrimInt; use std::fmt::Display; #[derive(Clone)] -pub struct SubCommand; +pub struct BitsRol; -impl Command for SubCommand { +impl Command for BitsRol { fn name(&self) -> &str { "bits rol" } @@ -155,6 +155,6 @@ mod test { fn test_examples() { use crate::test_examples; - test_examples(SubCommand {}) + test_examples(BitsRol {}) } } diff --git a/crates/nu-cmd-extra/src/extra/bits/rotate_right.rs b/crates/nu-cmd-extra/src/extra/bits/rotate_right.rs index 6c43c1554b..9e521a30e7 100644 --- a/crates/nu-cmd-extra/src/extra/bits/rotate_right.rs +++ b/crates/nu-cmd-extra/src/extra/bits/rotate_right.rs @@ -9,9 +9,9 @@ use num_traits::int::PrimInt; use std::fmt::Display; #[derive(Clone)] -pub struct SubCommand; +pub struct BitsRor; -impl Command for SubCommand { +impl Command for BitsRor { fn name(&self) -> &str { "bits ror" } @@ -159,6 +159,6 @@ mod test { fn test_examples() { use crate::test_examples; - test_examples(SubCommand {}) + test_examples(BitsRor {}) } } diff --git a/crates/nu-cmd-extra/src/extra/bits/shift_left.rs b/crates/nu-cmd-extra/src/extra/bits/shift_left.rs index 21d0a448ca..802b29a04f 100644 --- a/crates/nu-cmd-extra/src/extra/bits/shift_left.rs +++ b/crates/nu-cmd-extra/src/extra/bits/shift_left.rs @@ -9,9 +9,9 @@ use num_traits::CheckedShl; use std::fmt::Display; #[derive(Clone)] -pub struct SubCommand; +pub struct BitsShl; -impl Command for SubCommand { +impl Command for BitsShl { fn name(&self) -> &str { "bits shl" } @@ -178,6 +178,6 @@ mod test { fn test_examples() { use crate::test_examples; - test_examples(SubCommand {}) + test_examples(BitsShl {}) } } diff --git a/crates/nu-cmd-extra/src/extra/bits/shift_right.rs b/crates/nu-cmd-extra/src/extra/bits/shift_right.rs index 52965d2fa0..f780ee6672 100644 --- a/crates/nu-cmd-extra/src/extra/bits/shift_right.rs +++ b/crates/nu-cmd-extra/src/extra/bits/shift_right.rs @@ -9,9 +9,9 @@ use num_traits::CheckedShr; use std::fmt::Display; #[derive(Clone)] -pub struct SubCommand; +pub struct BitsShr; -impl Command for SubCommand { +impl Command for BitsShr { fn name(&self) -> &str { "bits shr" } @@ -168,6 +168,6 @@ mod test { fn test_examples() { use crate::test_examples; - test_examples(SubCommand {}) + test_examples(BitsShr {}) } } diff --git a/crates/nu-cmd-extra/src/extra/bits/xor.rs b/crates/nu-cmd-extra/src/extra/bits/xor.rs index 8ab888fc0f..691ea69079 100644 --- a/crates/nu-cmd-extra/src/extra/bits/xor.rs +++ b/crates/nu-cmd-extra/src/extra/bits/xor.rs @@ -6,9 +6,9 @@ use nu_protocol::{ }; #[derive(Clone)] -pub struct SubCommand; +pub struct BitsXor; -impl Command for SubCommand { +impl Command for BitsXor { fn name(&self) -> &str { "bits xor" } @@ -98,6 +98,6 @@ mod test { fn test_examples() { use crate::test_examples; - test_examples(SubCommand {}) + test_examples(BitsXor {}) } } diff --git a/crates/nu-cmd-extra/src/extra/mod.rs b/crates/nu-cmd-extra/src/extra/mod.rs index e63a5b1e14..125af37ebd 100644 --- a/crates/nu-cmd-extra/src/extra/mod.rs +++ b/crates/nu-cmd-extra/src/extra/mod.rs @@ -1,9 +1,26 @@ mod bits; -pub use bits::add_bits_decls; - use nu_protocol::engine::StateWorkingSet; pub fn add_extra_decls(working_set: &mut StateWorkingSet) { - add_bits_decls(working_set); + macro_rules! bind_command { + ( $command:expr ) => { + working_set.add_decl(Box::new($command)); + }; + ( $( $command:expr ),* ) => { + $( working_set.add_decl(Box::new($command)); )* + }; + } + + 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 + ); }