Files
chrome-use/cli/src/flags.rs
T
Coty RosenblathandClaude 5e94a18496 Fix CLI stripping --interactive and similar snapshot flags (#9)
* Fix --interactive flag being stripped for snapshot command

The clean_args function was removing all --prefixed arguments, which
incorrectly stripped command-specific flags like --interactive, --compact,
--depth, and --selector. Changed to only strip known global flags.

* Update Cargo.lock

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-01-11 23:17:13 -06:00

64 lines
1.6 KiB
Rust

use std::env;
pub struct Flags {
pub json: bool,
pub full: bool,
pub headed: bool,
pub debug: bool,
pub session: String,
}
pub fn parse_flags(args: &[String]) -> Flags {
let mut flags = Flags {
json: false,
full: false,
headed: false,
debug: false,
session: env::var("AGENT_BROWSER_SESSION").unwrap_or_else(|_| "default".to_string()),
};
let mut i = 0;
while i < args.len() {
match args[i].as_str() {
"--json" => flags.json = true,
"--full" | "-f" => flags.full = true,
"--headed" => flags.headed = true,
"--debug" => flags.debug = true,
"--session" => {
if let Some(s) = args.get(i + 1) {
flags.session = s.clone();
i += 1;
}
}
_ => {}
}
i += 1;
}
flags
}
pub fn clean_args(args: &[String]) -> Vec<String> {
let mut result = Vec::new();
let mut skip_next = false;
// Global flags that should be stripped from command args
const GLOBAL_FLAGS: &[&str] = &["--json", "--full", "--headed", "--debug"];
for arg in args.iter() {
if skip_next {
skip_next = false;
continue;
}
if arg == "--session" {
skip_next = true;
continue;
}
// Only strip known global flags, not command-specific flags
if GLOBAL_FLAGS.contains(&arg.as_str()) || arg == "-f" {
continue;
}
result.push(arg.clone());
}
result
}