mirror of
https://codeberg.org/schrottkatze/mgd2-tram-championships.git
synced 2025-07-04 11:07:40 +00:00
add debug console initial implementation
This commit is contained in:
parent
cf63dd6e41
commit
cf05050c95
13 changed files with 709 additions and 51 deletions
32
src/game/debug/console/cli.rs
Normal file
32
src/game/debug/console/cli.rs
Normal file
|
@ -0,0 +1,32 @@
|
|||
use clap::{Parser, Subcommand};
|
||||
|
||||
use crate::game::debug::DebugEvent;
|
||||
|
||||
pub(super) fn respond(line: &str) -> Result<DebugEvent, String> {
|
||||
let might_be_help_call = line.contains("help") || line.contains("-h");
|
||||
let args = shlex::split(line).ok_or("Invalid Quoting")?;
|
||||
let cli = Cli::try_parse_from(args).map_err(|e| e.to_string());
|
||||
|
||||
if might_be_help_call && cli.as_ref().is_err_and(|item| item.starts_with("Usage: ")) {
|
||||
let Err(s) = cli else { unreachable!() };
|
||||
return Ok(DebugEvent::PrintToConsole(s));
|
||||
}
|
||||
|
||||
Ok(match cli?.cmd {
|
||||
Commands::Close => DebugEvent::CloseDebugConsole,
|
||||
Commands::Echo { text } => DebugEvent::PrintToConsole(text),
|
||||
})
|
||||
}
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
#[command(multicall = true)]
|
||||
struct Cli {
|
||||
#[command(subcommand)]
|
||||
cmd: Commands,
|
||||
}
|
||||
|
||||
#[derive(Debug, Subcommand)]
|
||||
enum Commands {
|
||||
Close,
|
||||
Echo { text: String },
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue