initial commit (proof of concept build function, added cli structure

This commit is contained in:
2023-01-19 17:12:48 +01:00
commit b38bb186b1
12 changed files with 661 additions and 0 deletions

40
src/app/commands/mod.rs Normal file
View File

@@ -0,0 +1,40 @@
use std::collections::HashMap;
use traits::Command;
use self::build::Build;
pub mod traits;
mod build;
pub struct CommandRegistry {
commands: HashMap<String, Box<dyn Command>>
}
impl CommandRegistry {
pub fn register_all(&mut self) {
let registry = self;
registry.register("/build".to_string(), Box::new(Build::new()), true)
}
pub fn register(&mut self, path: String, command: Box<dyn Command>, enabled: bool) {
if enabled {
self.commands.insert(path, command);
}
}
pub fn new() -> CommandRegistry {
let mut registry = CommandRegistry { commands: HashMap::new() };
registry.register_all();
registry
}
pub fn command_by(&self, path: &String) -> Option<&Box<dyn Command>> {
let command = self.commands.get(path);
return command;
}
}