From 32e203b9080905c3292194f27fa6b3f669b22bce Mon Sep 17 00:00:00 2001 From: leeguooooo Date: Wed, 17 Jun 2026 01:33:22 +0900 Subject: [PATCH] style: cargo fmt (fixes the CI format-check failure) --- cli/src/commands.rs | 88 ++++++++++++++++++++++++++++------- cli/src/native/actions.rs | 24 ++++++---- cli/src/native/browser.rs | 32 ++++++++++--- cli/src/native/element.rs | 9 +++- cli/src/native/interaction.rs | 24 ++++++++-- cli/src/native/snapshot.rs | 11 ++++- cli/src/output.rs | 45 ++++++++++++++---- 7 files changed, 187 insertions(+), 46 deletions(-) diff --git a/cli/src/commands.rs b/cli/src/commands.rs index 41e23c2..9d49eff 100644 --- a/cli/src/commands.rs +++ b/cli/src/commands.rs @@ -34,11 +34,50 @@ pub enum ParseError { /// suggestions on an unknown command (issue #29). Not exhaustive — just the /// common verbs plus a few known wrong-guesses mapped to the real command. const KNOWN_COMMANDS: &[&str] = &[ - "open", "navigate", "click", "fill", "type", "press", "snapshot", "screenshot", "eval", "get", - "text", "html", "frames", "find", "wait", "scroll", "hover", "select", "check", "uncheck", - "tab", "tabs", "close", "back", "forward", "reload", "sessions", "status", "daemon", "doctor", - "upgrade", "connect", "cookies", "mouse", "keyboard", "stream", "frame", "profiles", "title", - "url", "is", "drag", "dialog", "upload", + "open", + "navigate", + "click", + "fill", + "type", + "press", + "snapshot", + "screenshot", + "eval", + "get", + "text", + "html", + "frames", + "find", + "wait", + "scroll", + "hover", + "select", + "check", + "uncheck", + "tab", + "tabs", + "close", + "back", + "forward", + "reload", + "sessions", + "status", + "daemon", + "doctor", + "upgrade", + "connect", + "cookies", + "mouse", + "keyboard", + "stream", + "frame", + "profiles", + "title", + "url", + "is", + "drag", + "dialog", + "upload", ]; /// Levenshtein distance, capped — small inputs only (command names). @@ -547,7 +586,9 @@ fn parse_command_inner(args: &[String], flags: &Flags) -> Result (or: type --focused ) [--key-events]", })?; - Ok(json!({ "id": id, "action": "type", "selector": sel, "text": rest[1..].join(" "), "keyEvents": key_events })) + Ok( + json!({ "id": id, "action": "type", "selector": sel, "text": rest[1..].join(" "), "keyEvents": key_events }), + ) } "pick" => { // pick --option "" — atomic combobox select: @@ -761,7 +802,8 @@ fn parse_command_inner(args: &[String], flags: &Flags) -> Result { return Err(ParseError::InvalidValue { message: format!("scroll --at: invalid coordinate `{}`", val), - usage: "scroll [direction] [amount] --at (e.g. --at 640,400)", + usage: + "scroll [direction] [amount] --at (e.g. --at 640,400)", }) } } @@ -970,17 +1012,21 @@ fn parse_command_inner(args: &[String], flags: &Flags) -> Result full_page = true, // `--clip x,y,w,h` captures a pixel region (issue #34). "--clip" => { - let raw = rest.get(i + 1).ok_or_else(|| ParseError::MissingArguments { - context: "screenshot --clip".to_string(), - usage: "screenshot --clip [path]", - })?; + let raw = rest + .get(i + 1) + .ok_or_else(|| ParseError::MissingArguments { + context: "screenshot --clip".to_string(), + usage: "screenshot --clip [path]", + })?; let nums: Vec = raw .split(',') .filter_map(|n| n.trim().parse::().ok()) .collect(); if nums.len() != 4 { return Err(ParseError::InvalidValue { - message: format!("--clip expects 'x,y,w,h' (4 numbers), got '{raw}'"), + message: format!( + "--clip expects 'x,y,w,h' (4 numbers), got '{raw}'" + ), usage: "screenshot --clip [path]", }); } @@ -4128,7 +4174,11 @@ mod tests { fn test_type_key_events() { // --key-events sends real keystrokes (for autocomplete/combobox) and must // not be swallowed into the typed text. - let cmd = parse_command(&args("type #postal 201-0001 --key-events"), &default_flags()).unwrap(); + let cmd = parse_command( + &args("type #postal 201-0001 --key-events"), + &default_flags(), + ) + .unwrap(); assert_eq!(cmd["action"], "type"); assert_eq!(cmd["selector"], "#postal"); assert_eq!(cmd["text"], "201-0001"); @@ -4426,8 +4476,11 @@ mod tests { #[test] fn test_screenshot_clip() { // `--clip x,y,w,h` captures a pixel region (issue #34); the path still parses. - let cmd = parse_command(&args("screenshot --clip 10,20,200,40 out.png"), &default_flags()) - .unwrap(); + let cmd = parse_command( + &args("screenshot --clip 10,20,200,40 out.png"), + &default_flags(), + ) + .unwrap(); assert_eq!(cmd["action"], "screenshot"); assert_eq!(cmd["clip"]["x"], 10.0); assert_eq!(cmd["clip"]["y"], 20.0); @@ -5005,7 +5058,10 @@ mod tests { assert_eq!(nearest_command("sesions").as_deref(), Some("sessions")); assert_eq!(nearest_command("session").as_deref(), Some("sessions")); assert_eq!(nearest_command("clik").as_deref(), Some("click")); - assert_eq!(nearest_command("screenshits").as_deref(), Some("screenshot")); + assert_eq!( + nearest_command("screenshits").as_deref(), + Some("screenshot") + ); // Nonsense with no close match stays silent. assert_eq!(nearest_command("xyzzy"), None); // The unknown-command error embeds the suggestion. diff --git a/cli/src/native/actions.rs b/cli/src/native/actions.rs index 7c9c9c8..e71d861 100644 --- a/cli/src/native/actions.rs +++ b/cli/src/native/actions.rs @@ -3244,8 +3244,14 @@ async fn handle_type(cmd: &Value, state: &mut DaemonState) -> Result Result Result { let mgr = state.browser.as_ref().ok_or("Browser not launched")?; let session_id = mgr.active_session_id()?.to_string(); - let frames = super::element::collect_all_frames_text( - &mgr.client, - &session_id, - &state.iframe_sessions, - ) - .await?; + let frames = + super::element::collect_all_frames_text(&mgr.client, &session_id, &state.iframe_sessions) + .await?; let list: Vec = frames .iter() .enumerate() @@ -4337,7 +4340,10 @@ async fn handle_cf_status(_cmd: &Value, state: &mut DaemonState) -> Result PageInfo { @@ -2931,7 +2943,10 @@ mod tests { let dirty = "\u{200d}\u{2061}\u{200d}\u{2063}\u{200b}\u{2062}\u{feff}GitHub"; assert_eq!(sanitize_title(dirty), "GitHub"); // Clean titles (incl. CJK + normal punctuation) pass through untouched. - assert_eq!(sanitize_title("購入手続きへ - メルカリ"), "購入手続きへ - メルカリ"); + assert_eq!( + sanitize_title("購入手続きへ - メルカリ"), + "購入手続きへ - メルカリ" + ); assert_eq!(sanitize_title(" Hello World "), "Hello World"); // Emoji and real content survive; only the invisibles are dropped. assert_eq!(sanitize_title("✓ Done\u{200b}"), "✓ Done"); @@ -2963,7 +2978,10 @@ mod tests { // A pinned target that IS in the live set is simply not prunable anyway. let mut live2 = HashSet::new(); live2.insert("A".to_string()); - assert_eq!(prunable_target_ids(&pages, &live2, Some("A")), vec!["B".to_string()]); + assert_eq!( + prunable_target_ids(&pages, &live2, Some("A")), + vec!["B".to_string()] + ); } #[test] diff --git a/cli/src/native/element.rs b/cli/src/native/element.rs index 500ef10..d823b4b 100644 --- a/cli/src/native/element.rs +++ b/cli/src/native/element.rs @@ -1028,7 +1028,9 @@ async fn eval_text_in_frame(client: &CdpClient, session_id: &str, frame_id: &str .await .ok() .and_then(|v| v.get("executionContextId").and_then(|c| c.as_i64())); - let Some(ctx_id) = ctx else { return String::new() }; + let Some(ctx_id) = ctx else { + return String::new(); + }; let res = client .send_command( "Runtime.evaluate", @@ -1099,7 +1101,10 @@ pub async fn collect_all_frames_text( let (kind, text) = if is_top { ("top", eval_text_default(client, top_session).await) } else { - ("inline", eval_text_in_frame(client, top_session, &fid).await) + ( + "inline", + eval_text_in_frame(client, top_session, &fid).await, + ) }; out.push(FrameText { frame_id: fid, diff --git a/cli/src/native/interaction.rs b/cli/src/native/interaction.rs index 46fb0f6..11a0c2d 100644 --- a/cli/src/native/interaction.rs +++ b/cli/src/native/interaction.rs @@ -65,7 +65,11 @@ pub async fn click( // the element's click in its own (frame) session, always hitting the right // element in the right tab. Double/right clicks still need true pointer // semantics, and `coord` mode is an explicit opt-out. - if mode != "coord" && button == "left" && click_count == 1 && prefer_dom_dispatch(ref_map, selector_or_ref) { + if mode != "coord" + && button == "left" + && click_count == 1 + && prefer_dom_dispatch(ref_map, selector_or_ref) + { return dom_click( client, session_id, @@ -319,7 +323,14 @@ pub async fn dblclick( if std::env::var("AGENT_BROWSER_CLICK_MODE").as_deref() != Ok("coord") && prefer_dom_dispatch(ref_map, selector_or_ref) { - return dom_dblclick(client, session_id, ref_map, selector_or_ref, iframe_sessions).await; + return dom_dblclick( + client, + session_id, + ref_map, + selector_or_ref, + iframe_sessions, + ) + .await; } click( client, @@ -387,7 +398,14 @@ pub async fn hover( // Coordinate `mouseMoved` drifts to the foreground tab over the relay and // can't reach an OOPIF — DOM-dispatch the hover there (issues #31/#36). if prefer_dom_dispatch(ref_map, selector_or_ref) { - return dom_hover(client, session_id, ref_map, selector_or_ref, iframe_sessions).await; + return dom_hover( + client, + session_id, + ref_map, + selector_or_ref, + iframe_sessions, + ) + .await; } let (x, y, _w, _h, effective_session_id) = resolve_element_center( client, diff --git a/cli/src/native/snapshot.rs b/cli/src/native/snapshot.rs index 09085d1..e387c4c 100644 --- a/cli/src/native/snapshot.rs +++ b/cli/src/native/snapshot.rs @@ -345,7 +345,16 @@ pub async fn take_snapshot( frame_id: Option<&str>, iframe_sessions: &HashMap, ) -> Result { - take_snapshot_at_depth(client, session_id, options, ref_map, frame_id, iframe_sessions, 0).await + take_snapshot_at_depth( + client, + session_id, + options, + ref_map, + frame_id, + iframe_sessions, + 0, + ) + .await } #[allow(clippy::too_many_arguments)] diff --git a/cli/src/output.rs b/cli/src/output.rs index 1aec9ea..50202f9 100644 --- a/cli/src/output.rs +++ b/cli/src/output.rs @@ -228,13 +228,28 @@ pub fn print_response_with_opts(resp: &Response, action: Option<&str>, opts: &Ou // because its response carries `url`/`title`, which later generic // renderers would otherwise swallow. if action == Some("cf_status") { - let challenged = data.get("challenged").and_then(|v| v.as_bool()).unwrap_or(false); - let rec = data.get("recommendation").and_then(|v| v.as_str()).unwrap_or("?"); + let challenged = data + .get("challenged") + .and_then(|v| v.as_bool()) + .unwrap_or(false); + let rec = data + .get("recommendation") + .and_then(|v| v.as_str()) + .unwrap_or("?"); let cl = data.get("clearance"); - let present = cl.and_then(|c| c.get("present")).and_then(|v| v.as_bool()).unwrap_or(false); - let expired = cl.and_then(|c| c.get("expired")).and_then(|v| v.as_bool()).unwrap_or(false); + let present = cl + .and_then(|c| c.get("present")) + .and_then(|v| v.as_bool()) + .unwrap_or(false); + let expired = cl + .and_then(|c| c.get("expired")) + .and_then(|v| v.as_bool()) + .unwrap_or(false); let expires_in = cl.and_then(|c| c.get("expiresIn")).and_then(|v| v.as_i64()); - let device = data.get("deviceVerified").and_then(|v| v.as_bool()).unwrap_or(false); + let device = data + .get("deviceVerified") + .and_then(|v| v.as_bool()) + .unwrap_or(false); let (icon, headline) = match rec { "proceed" => (color::success_indicator().to_string(), "cleared — no challenge, proceed"), @@ -243,7 +258,10 @@ pub fn print_response_with_opts(resp: &Response, action: Option<&str>, opts: &Ou _ => (color::cyan("•").to_string(), "unknown"), }; println!("{} {}", icon, headline); - println!(" challenged: {}", if challenged { "yes" } else { "no" }); + println!( + " challenged: {}", + if challenged { "yes" } else { "no" } + ); let cl_desc = if !present { "absent".to_string() } else if expired { @@ -254,7 +272,14 @@ pub fn print_response_with_opts(resp: &Response, action: Option<&str>, opts: &Ou "present (session)".to_string() }; println!(" cf_clearance: {}", cl_desc); - println!(" device trusted: {}", if device { "yes (CF_VERIFIED_DEVICE)" } else { "no" }); + println!( + " device trusted: {}", + if device { + "yes (CF_VERIFIED_DEVICE)" + } else { + "no" + } + ); return; } @@ -382,7 +407,11 @@ pub fn print_response_with_opts(resp: &Response, action: Option<&str>, opts: &Ou let count = list.len(); println!( "{}", - color::bold(&format!("{} frame{}", count, if count == 1 { "" } else { "s" })) + color::bold(&format!( + "{} frame{}", + count, + if count == 1 { "" } else { "s" } + )) ); for f in list { let idx = f.get("index").and_then(|v| v.as_i64()).unwrap_or(0);