@@ -6,6 +6,7 @@ pub struct Flags {
66 pub headed : bool ,
77 pub debug : bool ,
88 pub session : String ,
9+ pub executable_path : Option < String > ,
910}
1011
1112pub fn parse_flags ( args : & [ String ] ) -> Flags {
@@ -15,6 +16,7 @@ pub fn parse_flags(args: &[String]) -> Flags {
1516 headed : false ,
1617 debug : false ,
1718 session : env:: var ( "AGENT_BROWSER_SESSION" ) . unwrap_or_else ( |_| "default" . to_string ( ) ) ,
19+ executable_path : env:: var ( "AGENT_BROWSER_EXECUTABLE_PATH" ) . ok ( ) ,
1820 } ;
1921
2022 let mut i = 0 ;
@@ -30,6 +32,12 @@ pub fn parse_flags(args: &[String]) -> Flags {
3032 i += 1 ;
3133 }
3234 }
35+ "--executable-path" => {
36+ if let Some ( s) = args. get ( i + 1 ) {
37+ flags. executable_path = Some ( s. clone ( ) ) ;
38+ i += 1 ;
39+ }
40+ }
3341 _ => { }
3442 }
3543 i += 1 ;
@@ -43,13 +51,15 @@ pub fn clean_args(args: &[String]) -> Vec<String> {
4351
4452 // Global flags that should be stripped from command args
4553 const GLOBAL_FLAGS : & [ & str ] = & [ "--json" , "--full" , "--headed" , "--debug" ] ;
54+ // Flags that take a value (skip both the flag and the next arg)
55+ const VALUE_FLAGS : & [ & str ] = & [ "--session" , "--executable-path" ] ;
4656
4757 for arg in args. iter ( ) {
4858 if skip_next {
4959 skip_next = false ;
5060 continue ;
5161 }
52- if arg == "--session" {
62+ if VALUE_FLAGS . contains ( & arg. as_str ( ) ) {
5363 skip_next = true ;
5464 continue ;
5565 }
@@ -61,3 +71,43 @@ pub fn clean_args(args: &[String]) -> Vec<String> {
6171 }
6272 result
6373}
74+
75+ #[ cfg( test) ]
76+ mod tests {
77+ use super :: * ;
78+
79+ fn args ( s : & str ) -> Vec < String > {
80+ s. split_whitespace ( ) . map ( String :: from) . collect ( )
81+ }
82+
83+ #[ test]
84+ fn test_parse_executable_path_flag ( ) {
85+ let flags = parse_flags ( & args ( "--executable-path /path/to/chromium open example.com" ) ) ;
86+ assert_eq ! ( flags. executable_path, Some ( "/path/to/chromium" . to_string( ) ) ) ;
87+ }
88+
89+ #[ test]
90+ fn test_parse_executable_path_flag_no_value ( ) {
91+ let flags = parse_flags ( & args ( "--executable-path" ) ) ;
92+ assert_eq ! ( flags. executable_path, None ) ;
93+ }
94+
95+ #[ test]
96+ fn test_clean_args_removes_executable_path ( ) {
97+ let cleaned = clean_args ( & args ( "--executable-path /path/to/chromium open example.com" ) ) ;
98+ assert_eq ! ( cleaned, vec![ "open" , "example.com" ] ) ;
99+ }
100+
101+ #[ test]
102+ fn test_clean_args_removes_executable_path_with_other_flags ( ) {
103+ let cleaned = clean_args ( & args ( "--json --executable-path /path/to/chromium --headed open example.com" ) ) ;
104+ assert_eq ! ( cleaned, vec![ "open" , "example.com" ] ) ;
105+ }
106+
107+ #[ test]
108+ fn test_parse_flags_with_session_and_executable_path ( ) {
109+ let flags = parse_flags ( & args ( "--session test --executable-path /custom/chrome open example.com" ) ) ;
110+ assert_eq ! ( flags. session, "test" ) ;
111+ assert_eq ! ( flags. executable_path, Some ( "/custom/chrome" . to_string( ) ) ) ;
112+ }
113+ }
0 commit comments