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 args = shlex::split(line).ok_or("Invalid Quoting")?;
|
|
|
|
let cli = Cli::try_parse_from(args).map_err(|e| e.to_string());
|
|
|
|
|
2025-06-18 15:41:06 +02:00
|
|
|
// help detection
|
|
|
|
let command_contains_help = (line.contains("help") || line.contains("-h"));
|
|
|
|
let some_line_starts_with_usage = cli
|
|
|
|
.as_ref()
|
|
|
|
.is_err_and(|item| item.lines().any(|line| line.starts_with("Usage: ")));
|
|
|
|
|
|
|
|
if command_contains_help && some_line_starts_with_usage {
|
|
|
|
let Err(text) = cli else { unreachable!() };
|
|
|
|
return Ok(DebugEvent::PrintToConsole { text });
|
2025-06-17 20:50:46 +02:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|