forked from nonsensical-dev/zenyx-engine
remove categories
This commit is contained in:
parent
9a2cdd0cda
commit
47c67fb480
3 changed files with 4 additions and 47 deletions
|
@ -92,7 +92,6 @@ fn check_similarity(target: &str) -> Option<String> {
|
||||||
pub struct CommandManager {
|
pub struct CommandManager {
|
||||||
pub commands: HashMap<String, Box<dyn Command>>,
|
pub commands: HashMap<String, Box<dyn Command>>,
|
||||||
pub aliases: HashMap<String, String>,
|
pub aliases: HashMap<String, String>,
|
||||||
pub categories: HashMap<String, Category>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CommandManager {
|
impl CommandManager {
|
||||||
|
@ -100,14 +99,9 @@ impl CommandManager {
|
||||||
CommandManager {
|
CommandManager {
|
||||||
commands: HashMap::new(),
|
commands: HashMap::new(),
|
||||||
aliases: HashMap::new(),
|
aliases: HashMap::new(),
|
||||||
categories: HashMap::new(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_category(&mut self, category: Category) {
|
|
||||||
self.categories.insert(category.name.clone(), category);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_commands(&self) -> std::collections::hash_map::Iter<'_, String, Box<dyn Command>> {
|
pub fn get_commands(&self) -> std::collections::hash_map::Iter<'_, String, Box<dyn Command>> {
|
||||||
self.commands.iter()
|
self.commands.iter()
|
||||||
}
|
}
|
||||||
|
@ -146,16 +140,6 @@ impl CommandManager {
|
||||||
.insert(command.get_name().to_lowercase(), command);
|
.insert(command.get_name().to_lowercase(), command);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_command_with_category(&mut self, command: Box<dyn Command>, category: Category) {
|
|
||||||
if self.categories.contains_key(&category.name) {
|
|
||||||
let mut cmd_name = command.get_name().to_lowercase();
|
|
||||||
cmd_name.insert_str(0, &format!("{}_", &&category.uid.to_lowercase()));
|
|
||||||
println!("{}", cmd_name);
|
|
||||||
self.commands.insert(cmd_name, command);
|
|
||||||
} else {
|
|
||||||
panic!("Category {} does not exist", category.name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn add_alias(&mut self, alias: &str, command: &str) {
|
pub fn add_alias(&mut self, alias: &str, command: &str) {
|
||||||
self.aliases.insert(
|
self.aliases.insert(
|
||||||
|
@ -164,28 +148,7 @@ impl CommandManager {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub struct Category {
|
|
||||||
// eg: Zenyx -> Z
|
|
||||||
// eg: core -> cr
|
|
||||||
// eg: exitcmd -> cr_exit
|
|
||||||
// eg: echo -> z_echo
|
|
||||||
pub uid: String,
|
|
||||||
// eg: Zenyx
|
|
||||||
pub name: String,
|
|
||||||
// eg: Zenyx internal commands
|
|
||||||
pub description: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Category {
|
|
||||||
pub fn new(uid: &str, name: &str, description: &str) -> Self {
|
|
||||||
Self {
|
|
||||||
uid: uid.to_string(),
|
|
||||||
name: name.to_string(),
|
|
||||||
description: description.to_string(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait Command: Send + Sync {
|
pub trait Command: Send + Sync {
|
||||||
fn execute(&self, args: Option<Vec<String>>) -> Result<(), anyhow::Error>;
|
fn execute(&self, args: Option<Vec<String>>) -> Result<(), anyhow::Error>;
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
use commands::{
|
use commands::{
|
||||||
ClearCommand, CounterCommand, ExecFile, ExitCommand, HelpCommand, PanicCommmand
|
ClearCommand, CounterCommand, ExitCommand, HelpCommand, PanicCommmand,ExecFile
|
||||||
};
|
};
|
||||||
use handler::{COMMAND_MANAGER, Category};
|
|
||||||
use zlua::ZLua;
|
|
||||||
|
|
||||||
use crate::commands;
|
use crate::commands;
|
||||||
|
|
||||||
|
@ -14,15 +12,12 @@ pub mod zlua;
|
||||||
pub fn setup() {
|
pub fn setup() {
|
||||||
commands!(
|
commands!(
|
||||||
HelpCommand,
|
HelpCommand,
|
||||||
|
ExecFile,
|
||||||
|
|
||||||
ClearCommand,
|
ClearCommand,
|
||||||
ExitCommand,
|
ExitCommand,
|
||||||
CounterCommand,
|
CounterCommand,
|
||||||
PanicCommmand,
|
PanicCommmand,
|
||||||
zlua::ZLua
|
zlua::ZLua
|
||||||
);
|
);
|
||||||
let cat = Category::new("cr", "Core", "Core commands");
|
|
||||||
COMMAND_MANAGER.write().add_category(cat.clone());
|
|
||||||
COMMAND_MANAGER
|
|
||||||
.write()
|
|
||||||
.add_command_with_category(Box::new(ExecFile), cat.clone());
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,8 +84,7 @@ impl Command for ZLua {
|
||||||
..
|
..
|
||||||
}) => {
|
}) => {
|
||||||
// continue reading input and append it to `line`
|
// continue reading input and append it to `line`
|
||||||
line.push_str("\n"); // separate input lines
|
line.push('\n'); // separate input lines
|
||||||
prompt = prompt;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue