Improved CLI

This commit is contained in:
2025-12-21 14:55:21 +01:00
parent 8062cfc8fa
commit c45f9a59ca
2 changed files with 24 additions and 7 deletions
+1
View File
@@ -10,6 +10,7 @@ chrono = "0.4.42"
once_cell = "1.21.3" once_cell = "1.21.3"
rand = "0.9.2" rand = "0.9.2"
rusqlite = "0.37.0" rusqlite = "0.37.0"
rustyline = "17.0.2"
serde = { version = "1.0.219", features = ["serde_derive"] } serde = { version = "1.0.219", features = ["serde_derive"] }
serde_json = "1.0.143" serde_json = "1.0.143"
sha1 = "0.10.6" sha1 = "0.10.6"
+23 -7
View File
@@ -1,5 +1,6 @@
use std::{fs::File, io, path::PathBuf, str::FromStr, sync::Arc}; use std::{fs::File, path::PathBuf, str::FromStr, sync::Arc};
use rustyline::{DefaultEditor, error::ReadlineError};
use zip::ZipArchive; use zip::ZipArchive;
use crate::{logger, plugin::loader::PluginLoader, server::Server}; use crate::{logger, plugin::loader::PluginLoader, server::Server};
@@ -65,11 +66,24 @@ pub fn require_args(args: &[String], required: &[&str]) -> bool {
pub fn start_cli(server: Arc<Server>, plugin_loader: PluginLoader) { pub fn start_cli(server: Arc<Server>, plugin_loader: PluginLoader) {
std::thread::spawn(move || { std::thread::spawn(move || {
let mut rl = DefaultEditor::new().unwrap();
loop { loop {
let mut buf = String::new(); let line = match rl.readline("> ") {
io::stdin().read_line(&mut buf).unwrap(); Ok(line) => {
let args = parse_args(buf.trim()); rl.add_history_entry(line.as_str()).ok();
if args.len() == 0 { line
}
Err(ReadlineError::Interrupted) => continue,
Err(ReadlineError::Eof) => break,
Err(err) => {
LOGGER.error(format!("CLI error: {:?}", err));
break;
}
};
let args = parse_args(line.trim());
if args.is_empty() {
continue; continue;
} }
@@ -85,6 +99,7 @@ pub fn start_cli(server: Arc<Server>, plugin_loader: PluginLoader) {
let mut archive = ZipArchive::new(file).unwrap(); let mut archive = ZipArchive::new(file).unwrap();
archive.extract(&d).unwrap(); archive.extract(&d).unwrap();
} }
LOGGER.info("Installed");
} else { } else {
LOGGER.error("File must be .vxp"); LOGGER.error("File must be .vxp");
} }
@@ -95,9 +110,10 @@ pub fn start_cli(server: Arc<Server>, plugin_loader: PluginLoader) {
plugin_loader.load(&server.root.join("plugins").join(&args[1])); plugin_loader.load(&server.root.join("plugins").join(&args[1]));
} }
} }
_ => { "ping" => {
LOGGER.error(format!("Command not found ({})", args[0])); LOGGER.info("pong");
} }
_ => LOGGER.error(format!("Command not found: {}", args[0])),
} }
} }
}); });