fix(cli): Output screenshot as base64 string when no path provided (#83)
* fix(cli): print screenshot base64 when no path * chore(docs): update docs and SKILL.md * add test for screenshot with path arg * more minimal readme + skill change
This commit is contained in:
+13
-1
@@ -273,7 +273,11 @@ pub fn parse_command(args: &[String], flags: &Flags) -> Result<Value, ParseError
|
||||
|
||||
// === Screenshot/PDF ===
|
||||
"screenshot" => {
|
||||
Ok(json!({ "id": id, "action": "screenshot", "path": rest.get(0), "fullPage": flags.full }))
|
||||
let mut cmd = json!({ "id": id, "action": "screenshot", "fullPage": flags.full });
|
||||
if let Some(path) = rest.get(0) {
|
||||
cmd["path"] = json!(path);
|
||||
}
|
||||
Ok(cmd)
|
||||
}
|
||||
"pdf" => {
|
||||
let path = rest.get(0).ok_or_else(|| ParseError::MissingArguments {
|
||||
@@ -1286,6 +1290,14 @@ mod tests {
|
||||
fn test_screenshot() {
|
||||
let cmd = parse_command(&args("screenshot"), &default_flags()).unwrap();
|
||||
assert_eq!(cmd["action"], "screenshot");
|
||||
assert!(cmd.get("path").is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_screenshot_path() {
|
||||
let cmd = parse_command(&args("screenshot out.png"), &default_flags()).unwrap();
|
||||
assert_eq!(cmd["action"], "screenshot");
|
||||
assert_eq!(cmd["path"], "out.png");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -208,6 +208,11 @@ pub fn print_response(resp: &Response, json_mode: bool) {
|
||||
println!("\x1b[32m✓\x1b[0m Screenshot saved to {}", path);
|
||||
return;
|
||||
}
|
||||
// Screenshot base64
|
||||
if let Some(base64) = data.get("base64").and_then(|v| v.as_str()) {
|
||||
println!("{}", base64);
|
||||
return;
|
||||
}
|
||||
// Default success
|
||||
println!("\x1b[32m✓\x1b[0m Done");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user