From e7a8a709ef050e863189f48004903679bb796a67 Mon Sep 17 00:00:00 2001 From: ldm0 Date: Fri, 21 Aug 2026 21:05:00 +0800 Subject: [PATCH] refactor(cli): encapsulate response body regex --- moli/src/cli.rs | 21 +++++++++++++++++++-- moli/src/config.rs | 2 +- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/moli/src/cli.rs b/moli/src/cli.rs index 92a852aa77..83163bf9a0 100644 --- a/moli/src/cli.rs +++ b/moli/src/cli.rs @@ -96,7 +96,11 @@ pub struct FetchArgs { /// Wait for a response whose body matches this regex. An invalid regex /// fails the fetch command immediately. - #[arg(long, value_parser = parse_response_body_regex)] + #[arg( + long, + value_name = "REGEX", + value_parser = parse_response_body_regex + )] pub wait_response_body: Option, #[arg(long, value_parser = parse_response_json_path_arg)] @@ -171,10 +175,14 @@ fn parse_response_json_path_arg(raw: &str) -> Result &Regex { + &self.regex + } + pub fn pattern(&self) -> &str { self.regex.as_str() } @@ -592,6 +600,15 @@ mod tests { assert!(help.contains("response match, selector, and script waits share one absolute")); } + #[test] + fn fetch_help_labels_response_body_pattern_as_regex() { + let help = Cli::try_parse_from(["moli", "fetch", "--help"]) + .unwrap_err() + .to_string(); + + assert!(help.contains("--wait-response-body ")); + } + #[test] fn parses_port_equals_with_explicit_serve_command() { let args = normalize_args_for_compat(["moli", "serve", "--port=0"]); diff --git a/moli/src/config.rs b/moli/src/config.rs index 2311a33b0c..e95dd76280 100644 --- a/moli/src/config.rs +++ b/moli/src/config.rs @@ -302,7 +302,7 @@ pub fn response_wait_criteria_from_args( body_regex: args .wait_response_body .as_ref() - .map(|arg| arg.regex.clone()), + .map(|arg| arg.regex().clone()), json_path_equals: args .wait_response_json .as_ref()