feat: dabble with macros a bit more
This commit is contained in:
parent
826a914c8f
commit
f362a01e0c
1 changed files with 25 additions and 18 deletions
|
|
@ -1,26 +1,33 @@
|
|||
use super::boxcmd::Boxcmd;
|
||||
use crate::boxcmd::Boxcmd;
|
||||
use boxutils::registry::CommandRegistry;
|
||||
|
||||
macro_rules! register {
|
||||
($registry:expr, { $($cmd_name:expr => $cmd:expr),* }) => {
|
||||
$(
|
||||
$registry.register($cmd_name, Box::new($cmd));
|
||||
)*
|
||||
};
|
||||
}
|
||||
|
||||
pub fn get_registry() -> CommandRegistry {
|
||||
let mut registry = CommandRegistry::new();
|
||||
|
||||
registry.register("hello", Box::new(coreutils::commands::Hello));
|
||||
registry.register("cat", Box::new(coreutils::commands::Cat));
|
||||
registry.register("echo", Box::new(coreutils::commands::Echo));
|
||||
registry.register("mkdir", Box::new(coreutils::commands::Mkdir));
|
||||
registry.register("ash", Box::new(shell::ash::Ash));
|
||||
registry.register("dd", Box::new(coreutils::commands::Dd));
|
||||
registry.register("nproc", Box::new(coreutils::commands::Nproc));
|
||||
registry.register("true", Box::new(coreutils::commands::True));
|
||||
registry.register("false", Box::new(coreutils::commands::False));
|
||||
registry.register(
|
||||
"test",
|
||||
Box::new(coreutils::commands::Test::without_bracket()),
|
||||
);
|
||||
registry.register("[", Box::new(coreutils::commands::Test::with_bracket()));
|
||||
registry.register("yes", Box::new(coreutils::commands::Yes));
|
||||
registry.register("pwd", Box::new(coreutils::commands::Pwd));
|
||||
registry.register("box", Box::new(Boxcmd));
|
||||
register!(registry, {
|
||||
"hello" => coreutils::commands::Hello,
|
||||
"cat" => coreutils::commands::Cat,
|
||||
"echo" => coreutils::commands::Echo,
|
||||
"mkdir" => coreutils::commands::Mkdir,
|
||||
"ash" => shell::ash::Ash,
|
||||
"dd" => coreutils::commands::Dd,
|
||||
"nproc" => coreutils::commands::Nproc,
|
||||
"true" => coreutils::commands::True,
|
||||
"false" => coreutils::commands::False,
|
||||
"test" => coreutils::commands::Test::without_bracket(),
|
||||
"[" => coreutils::commands::Test::with_bracket(),
|
||||
"yes" => coreutils::commands::Yes,
|
||||
"pwd" => coreutils::commands::Pwd,
|
||||
"box" => Boxcmd
|
||||
});
|
||||
|
||||
registry
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue