2025-06-17 20:50:46 +02:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2025-06-18 15:40:33 +02:00
|
|
|
Ok(cli?.cmd)
|
2025-06-17 20:50:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Parser)]
|
|
|
|
#[command(multicall = true)]
|
|
|
|
struct Cli {
|
|
|
|
#[command(subcommand)]
|
2025-06-18 15:40:33 +02:00
|
|
|
cmd: DebugEvent,
|
2025-06-17 20:50:46 +02:00
|
|
|
}
|