split up main.rs

This commit is contained in:
Chris Tate
2026-01-11 10:04:24 -06:00
parent 9e31100dcb
commit ee4eacff27
6 changed files with 1101 additions and 954 deletions
+58
View File
@@ -0,0 +1,58 @@
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;
for arg in args.iter() {
if skip_next {
skip_next = false;
continue;
}
if arg == "--session" {
skip_next = true;
continue;
}
if !arg.starts_with("--") && arg != "-f" {
result.push(arg.clone());
}
}
result
}