@@ -70,19 +70,22 @@ impl CommandLineArgsParser {
7070 }
7171
7272 fn parse_argument_group ( & self , argument_group : Vec < String > ) -> Option < OwnedCommandAndArgs > {
73+ let first_command_and_args = & self . argument_groups . first_command_and_args ;
74+
7375 let cmd_and_args = if !self . regex_processor . regex_mode ( ) {
74- [
75- self . argument_groups . first_command_and_args . clone ( ) ,
76- argument_group,
77- ]
78- . concat ( )
76+ [ first_command_and_args. clone ( ) , argument_group] . concat ( )
7977 } else {
8078 let input_line = argument_group. join ( " " ) ;
8179
82- self . regex_processor . apply_regex_to_arguments (
83- & self . argument_groups . first_command_and_args ,
84- & input_line,
85- ) ?
80+ let apply_regex_result = self
81+ . regex_processor
82+ . apply_regex_to_arguments ( first_command_and_args, & input_line) ?;
83+
84+ if apply_regex_result. modified_arguments {
85+ apply_regex_result. arguments
86+ } else {
87+ [ first_command_and_args. clone ( ) , argument_group] . concat ( )
88+ }
8689 } ;
8790
8891 super :: build_owned_command_and_args ( & self . shell_command_and_args , cmd_and_args)
@@ -455,4 +458,58 @@ mod test {
455458 ]
456459 ) ;
457460 }
461+
462+ #[ test]
463+ fn test_auto_regex ( ) {
464+ let command_line_args = CommandLineArgs {
465+ command_and_initial_arguments : [
466+ "echo" , "got" , "arg1={1}" , "arg2={2}" , ":::" , "foo" , "bar" , ":::" , "baz" , "qux" ,
467+ ]
468+ . into_iter ( )
469+ . map_into ( )
470+ . collect ( ) ,
471+ ..Default :: default ( )
472+ } ;
473+
474+ let parser = CommandLineArgsParser :: new (
475+ & command_line_args,
476+ & RegexProcessor :: new ( & command_line_args) . unwrap ( ) ,
477+ ) ;
478+
479+ let result = collect_into_vec ( parser) ;
480+
481+ assert_eq ! (
482+ result,
483+ vec![
484+ OwnedCommandAndArgs {
485+ command_path: PathBuf :: from( "echo" ) ,
486+ args: [ "got" , "arg1=foo" , "arg2=baz" ]
487+ . into_iter( )
488+ . map_into( )
489+ . collect( ) ,
490+ } ,
491+ OwnedCommandAndArgs {
492+ command_path: PathBuf :: from( "echo" ) ,
493+ args: [ "got" , "arg1=foo" , "arg2=qux" ]
494+ . into_iter( )
495+ . map_into( )
496+ . collect( ) ,
497+ } ,
498+ OwnedCommandAndArgs {
499+ command_path: PathBuf :: from( "echo" ) ,
500+ args: [ "got" , "arg1=bar" , "arg2=baz" ]
501+ . into_iter( )
502+ . map_into( )
503+ . collect( ) ,
504+ } ,
505+ OwnedCommandAndArgs {
506+ command_path: PathBuf :: from( "echo" ) ,
507+ args: [ "got" , "arg1=bar" , "arg2=qux" ]
508+ . into_iter( )
509+ . map_into( )
510+ . collect( ) ,
511+ } ,
512+ ]
513+ ) ;
514+ }
458515}
0 commit comments