mirror of
https://codeberg.org/schrottkatze/mgd2-tram-championships.git
synced 2025-07-02 01:27:39 +00:00
make help detection slightly more readable
This commit is contained in:
parent
3157af2c2b
commit
4b71994b6b
1 changed files with 9 additions and 4 deletions
|
@ -3,13 +3,18 @@ use clap::{Parser, Subcommand};
|
||||||
use crate::game::debug::DebugEvent;
|
use crate::game::debug::DebugEvent;
|
||||||
|
|
||||||
pub(super) fn respond(line: &str) -> Result<DebugEvent, String> {
|
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 args = shlex::split(line).ok_or("Invalid Quoting")?;
|
||||||
let cli = Cli::try_parse_from(args).map_err(|e| e.to_string());
|
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: ")) {
|
// help detection
|
||||||
let Err(s) = cli else { unreachable!() };
|
let command_contains_help = (line.contains("help") || line.contains("-h"));
|
||||||
return Ok(DebugEvent::PrintToConsole(s));
|
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 });
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(cli?.cmd)
|
Ok(cli?.cmd)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue