From 4b71994b6b2156a74be24a39e93f892fd15f72af Mon Sep 17 00:00:00 2001 From: Schrottkatze Date: Wed, 18 Jun 2025 15:41:06 +0200 Subject: [PATCH] make help detection slightly more readable --- src/game/debug/console/cli.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/game/debug/console/cli.rs b/src/game/debug/console/cli.rs index 0441504..ecdf825 100644 --- a/src/game/debug/console/cli.rs +++ b/src/game/debug/console/cli.rs @@ -3,13 +3,18 @@ use clap::{Parser, Subcommand}; use crate::game::debug::DebugEvent; pub(super) fn respond(line: &str) -> Result { - 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)); + // 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 }); } Ok(cli?.cmd)