nushell/crates/nu-cmd-extra/src/extra/mod.rs
Antoine Stevan 9fcc49e556
REFACTOR: simplify the declaration of extra commands (#9398)
cc/ @stormasm 

# Description
i was about to start the cratification of the 0% commands and thought i
could refactor and simplify a bit the declaration of the `bits`
commands, having hopefully a simpler structure to work with the other
commands 😌

this PR:
- gives real names to all the `bits` commands, instead of `SubCommand`
- make them publicly available inside the `nu-cmd-extra` crate to
declare them through `add_extra_decls`
- move the declaration code to the top-level `mod.nu` of `nu-cmd-extra`
so that all commands can be declared there as in `default_context` in
`nu-command`

# User-Facing Changes
```
$nothing
```

# Tests + Formatting
- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
-  `toolkit test`
-  `toolkit test stdlib`

# After Submitting
```
$nothing
```
2023-06-10 10:33:33 -07:00

27 lines
694 B
Rust

mod bits;
use nu_protocol::engine::StateWorkingSet;
pub fn add_extra_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)); )*
};
}
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
);
}