feat: enhance response output with network request details and cleared status (#117)
This commit is contained in:
+30
-6
@@ -385,7 +385,11 @@ pub fn parse_command(args: &[String], flags: &Flags) -> Result<Value, ParseError
|
|||||||
}
|
}
|
||||||
Some("list") => Ok(json!({ "id": id, "action": "tab_list" })),
|
Some("list") => Ok(json!({ "id": id, "action": "tab_list" })),
|
||||||
Some("close") => {
|
Some("close") => {
|
||||||
Ok(json!({ "id": id, "action": "tab_close", "index": rest.get(1).and_then(|s| s.parse::<i32>().ok()) }))
|
let mut cmd = json!({ "id": id, "action": "tab_close" });
|
||||||
|
if let Some(index) = rest.get(1).and_then(|s| s.parse::<i32>().ok()) {
|
||||||
|
cmd["index"] = json!(index);
|
||||||
|
}
|
||||||
|
Ok(cmd)
|
||||||
}
|
}
|
||||||
Some(n) if n.parse::<i32>().is_ok() => {
|
Some(n) if n.parse::<i32>().is_ok() => {
|
||||||
Ok(json!({ "id": id, "action": "tab_switch", "index": n.parse::<i32>().unwrap() }))
|
Ok(json!({ "id": id, "action": "tab_switch", "index": n.parse::<i32>().unwrap() }))
|
||||||
@@ -428,7 +432,11 @@ pub fn parse_command(args: &[String], flags: &Flags) -> Result<Value, ParseError
|
|||||||
const VALID: &[&str] = &["accept", "dismiss"];
|
const VALID: &[&str] = &["accept", "dismiss"];
|
||||||
match rest.get(0).map(|s| *s) {
|
match rest.get(0).map(|s| *s) {
|
||||||
Some("accept") => {
|
Some("accept") => {
|
||||||
Ok(json!({ "id": id, "action": "dialog", "response": "accept", "promptText": rest.get(1) }))
|
let mut cmd = json!({ "id": id, "action": "dialog", "response": "accept" });
|
||||||
|
if let Some(prompt_text) = rest.get(1) {
|
||||||
|
cmd["promptText"] = json!(prompt_text);
|
||||||
|
}
|
||||||
|
Ok(cmd)
|
||||||
}
|
}
|
||||||
Some("dismiss") => Ok(json!({ "id": id, "action": "dialog", "response": "dismiss" })),
|
Some("dismiss") => Ok(json!({ "id": id, "action": "dialog", "response": "dismiss" })),
|
||||||
Some(sub) => Err(ParseError::UnknownSubcommand {
|
Some(sub) => Err(ParseError::UnknownSubcommand {
|
||||||
@@ -446,8 +454,14 @@ pub fn parse_command(args: &[String], flags: &Flags) -> Result<Value, ParseError
|
|||||||
"trace" => {
|
"trace" => {
|
||||||
const VALID: &[&str] = &["start", "stop"];
|
const VALID: &[&str] = &["start", "stop"];
|
||||||
match rest.get(0).map(|s| *s) {
|
match rest.get(0).map(|s| *s) {
|
||||||
Some("start") => Ok(json!({ "id": id, "action": "trace_start", "path": rest.get(1) })),
|
Some("start") => Ok(json!({ "id": id, "action": "trace_start" })),
|
||||||
Some("stop") => Ok(json!({ "id": id, "action": "trace_stop", "path": rest.get(1) })),
|
Some("stop") => {
|
||||||
|
let path = rest.get(1).ok_or_else(|| ParseError::MissingArguments {
|
||||||
|
context: "trace stop".to_string(),
|
||||||
|
usage: "trace stop <path>",
|
||||||
|
})?;
|
||||||
|
Ok(json!({ "id": id, "action": "trace_stop", "path": path }))
|
||||||
|
},
|
||||||
Some(sub) => Err(ParseError::UnknownSubcommand {
|
Some(sub) => Err(ParseError::UnknownSubcommand {
|
||||||
subcommand: sub.to_string(),
|
subcommand: sub.to_string(),
|
||||||
valid_options: VALID,
|
valid_options: VALID,
|
||||||
@@ -934,12 +948,22 @@ fn parse_network(rest: &[&str], id: &str) -> Result<Value, ParseError> {
|
|||||||
let body = body_idx.and_then(|i| rest.get(i + 1).map(|s| *s));
|
let body = body_idx.and_then(|i| rest.get(i + 1).map(|s| *s));
|
||||||
Ok(json!({ "id": id, "action": "route", "url": url, "abort": abort, "body": body }))
|
Ok(json!({ "id": id, "action": "route", "url": url, "abort": abort, "body": body }))
|
||||||
}
|
}
|
||||||
Some("unroute") => Ok(json!({ "id": id, "action": "unroute", "url": rest.get(1) })),
|
Some("unroute") => {
|
||||||
|
let mut cmd = json!({ "id": id, "action": "unroute" });
|
||||||
|
if let Some(url) = rest.get(1) {
|
||||||
|
cmd["url"] = json!(url);
|
||||||
|
}
|
||||||
|
Ok(cmd)
|
||||||
|
},
|
||||||
Some("requests") => {
|
Some("requests") => {
|
||||||
let clear = rest.iter().any(|&s| s == "--clear");
|
let clear = rest.iter().any(|&s| s == "--clear");
|
||||||
let filter_idx = rest.iter().position(|&s| s == "--filter");
|
let filter_idx = rest.iter().position(|&s| s == "--filter");
|
||||||
let filter = filter_idx.and_then(|i| rest.get(i + 1).map(|s| *s));
|
let filter = filter_idx.and_then(|i| rest.get(i + 1).map(|s| *s));
|
||||||
Ok(json!({ "id": id, "action": "requests", "clear": clear, "filter": filter }))
|
let mut cmd = json!({ "id": id, "action": "requests", "clear": clear });
|
||||||
|
if let Some(f) = filter {
|
||||||
|
cmd["filter"] = json!(f);
|
||||||
|
}
|
||||||
|
Ok(cmd)
|
||||||
}
|
}
|
||||||
Some(sub) => Err(ParseError::UnknownSubcommand {
|
Some(sub) => Err(ParseError::UnknownSubcommand {
|
||||||
subcommand: sub.to_string(),
|
subcommand: sub.to_string(),
|
||||||
|
|||||||
@@ -118,6 +118,27 @@ pub fn print_response(resp: &Response, json_mode: bool) {
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// Network requests
|
||||||
|
if let Some(requests) = data.get("requests").and_then(|v| v.as_array()) {
|
||||||
|
if requests.is_empty() {
|
||||||
|
println!("No requests captured");
|
||||||
|
} else {
|
||||||
|
for req in requests {
|
||||||
|
let method = req.get("method").and_then(|v| v.as_str()).unwrap_or("GET");
|
||||||
|
let url = req.get("url").and_then(|v| v.as_str()).unwrap_or("");
|
||||||
|
let resource_type = req.get("resourceType").and_then(|v| v.as_str()).unwrap_or("");
|
||||||
|
println!("{} {} ({})", method, url, resource_type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Cleared requests
|
||||||
|
if let Some(cleared) = data.get("cleared").and_then(|v| v.as_bool()) {
|
||||||
|
if cleared {
|
||||||
|
println!("\x1b[32m✓\x1b[0m Request log cleared");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
// Bounding box
|
// Bounding box
|
||||||
if let Some(box_data) = data.get("box") {
|
if let Some(box_data) = data.get("box") {
|
||||||
println!(
|
println!(
|
||||||
|
|||||||
Reference in New Issue
Block a user