@@ -1726,10 +1726,30 @@ fn analyze_silver_searcher(
17261726 index += 2 ;
17271727 continue ;
17281728 }
1729+ if token == "--ignore-dir"
1730+ || token == "--depth"
1731+ || token == "--max-count"
1732+ || token == "--pager"
1733+ || token == "--workers"
1734+ {
1735+ index += 2 ;
1736+ continue ;
1737+ }
17291738 if token == "--file-search-regex" {
17301739 index += 2 ;
17311740 continue ;
17321741 }
1742+ if token == "--after" || token == "--before" || token == "--context" {
1743+ if argv
1744+ . get ( index + 1 )
1745+ . is_some_and ( |value| looks_like_integer ( value. as_str ( ) ) )
1746+ {
1747+ index += 2 ;
1748+ } else {
1749+ index += 1 ;
1750+ }
1751+ continue ;
1752+ }
17331753 if token == "--path-to-ignore" {
17341754 if let Some ( value) = argv. get ( index + 1 ) {
17351755 push_inferred_input ( & mut inputs, value. as_str ( ) , cwd) ?;
@@ -1746,7 +1766,16 @@ fn analyze_silver_searcher(
17461766 index += 1 ;
17471767 continue ;
17481768 }
1749- if token. starts_with ( "--ignore=" ) {
1769+ if token. starts_with ( "--ignore=" )
1770+ || token. starts_with ( "--ignore-dir=" )
1771+ || token. starts_with ( "--depth=" )
1772+ || token. starts_with ( "--max-count=" )
1773+ || token. starts_with ( "--pager=" )
1774+ || token. starts_with ( "--workers=" )
1775+ || token. starts_with ( "--after=" )
1776+ || token. starts_with ( "--before=" )
1777+ || token. starts_with ( "--context=" )
1778+ {
17501779 index += 1 ;
17511780 continue ;
17521781 }
@@ -1780,6 +1809,11 @@ fn analyze_silver_searcher(
17801809 index += 2 ;
17811810 continue ;
17821811 }
1812+ SilverSearcherShortOption :: ControlValueInline => { }
1813+ SilverSearcherShortOption :: ControlValueNext => {
1814+ index += 2 ;
1815+ continue ;
1816+ }
17831817 }
17841818 index += 1 ;
17851819 continue ;
@@ -1822,6 +1856,8 @@ enum SilverSearcherShortOption<'a> {
18221856 FileSearchRegexNext ,
18231857 PathToIgnoreInline ( & ' a str ) ,
18241858 PathToIgnoreNext ,
1859+ ControlValueInline ,
1860+ ControlValueNext ,
18251861}
18261862
18271863fn parse_silver_searcher_short_option ( token : & str ) -> Option < SilverSearcherShortOption < ' _ > > {
@@ -1841,6 +1877,8 @@ fn parse_silver_searcher_short_option(token: &str) -> Option<SilverSearcherShort
18411877 return Some ( SilverSearcherShortOption :: FileSearchRegexNext ) ;
18421878 }
18431879 'G' => return Some ( SilverSearcherShortOption :: FileSearchRegexInline ) ,
1880+ 'm' if value. is_empty ( ) => return Some ( SilverSearcherShortOption :: ControlValueNext ) ,
1881+ 'm' => return Some ( SilverSearcherShortOption :: ControlValueInline ) ,
18441882 'p' if value. is_empty ( ) => return Some ( SilverSearcherShortOption :: PathToIgnoreNext ) ,
18451883 'p' => return Some ( SilverSearcherShortOption :: PathToIgnoreInline ( value) ) ,
18461884 _ => { }
@@ -3024,6 +3062,13 @@ fn analyze_capnp(
30243062 index += 2 ;
30253063 continue ;
30263064 }
3065+ if token == "--import-path" {
3066+ if let Some ( value) = argv. get ( index + 1 ) {
3067+ push_inferred_input ( & mut inputs, value. as_str ( ) , cwd) ?;
3068+ }
3069+ index += 2 ;
3070+ continue ;
3071+ }
30273072 if token == "-o" {
30283073 filtered_output_count += usize:: from ( argv. get ( index + 1 ) . is_some ( ) ) ;
30293074 index += 2 ;
@@ -3034,6 +3079,11 @@ fn analyze_capnp(
30343079 index += 1 ;
30353080 continue ;
30363081 }
3082+ if let Some ( value) = token. strip_prefix ( "--import-path=" ) {
3083+ push_inferred_input ( & mut inputs, value, cwd) ?;
3084+ index += 1 ;
3085+ continue ;
3086+ }
30373087 if token. starts_with ( "-o" ) && token. len ( ) > 2 {
30383088 filtered_output_count += 1 ;
30393089 index += 1 ;
@@ -3480,6 +3530,10 @@ fn has_glob_magic(raw: &str) -> bool {
34803530 raw. contains ( '*' ) || raw. contains ( '?' ) || raw. contains ( '[' )
34813531}
34823532
3533+ fn looks_like_integer ( raw : & str ) -> bool {
3534+ raw. parse :: < i64 > ( ) . is_ok ( )
3535+ }
3536+
34833537fn path_exists ( raw : & str , cwd : & Path ) -> bool {
34843538 absolutize ( raw, cwd) . exists ( )
34853539}
@@ -3777,6 +3831,22 @@ mod tests {
37773831 & [ cwd. path ( ) . join ( ".agignore" ) , cwd. path ( ) . join ( "src" ) ] ,
37783832 ) ;
37793833
3834+ let ag_with_long_value_flag = analyze_argv (
3835+ & [
3836+ OsString :: from ( "ag" ) ,
3837+ OsString :: from ( "--depth" ) ,
3838+ OsString :: from ( "2" ) ,
3839+ OsString :: from ( "TODO" ) ,
3840+ ] ,
3841+ cwd. path ( ) ,
3842+ )
3843+ . expect ( "analyze" ) ;
3844+ assert_eq ! (
3845+ ag_with_long_value_flag. adapter_ids,
3846+ vec![ CommandAdapterId :: SilverSearcher ]
3847+ ) ;
3848+ assert ! ( ag_with_long_value_flag. inputs. is_empty( ) ) ;
3849+
37803850 let ag_with_filename_pattern = analyze_argv (
37813851 & [
37823852 OsString :: from ( "ag" ) ,
@@ -4049,6 +4119,27 @@ mod tests {
40494119 & capnp,
40504120 & [ cwd. path ( ) . join ( "schemas" ) , cwd. path ( ) . join ( "schema.capnp" ) ] ,
40514121 ) ;
4122+
4123+ let capnp_with_long_import_path = analyze_argv (
4124+ & [
4125+ OsString :: from ( "capnp" ) ,
4126+ OsString :: from ( "compile" ) ,
4127+ OsString :: from ( "--import-path=schemas" ) ,
4128+ OsString :: from ( "-oc++" ) ,
4129+ OsString :: from ( "schema.capnp" ) ,
4130+ ] ,
4131+ cwd. path ( ) ,
4132+ )
4133+ . expect ( "analyze" ) ;
4134+ assert_eq ! (
4135+ capnp_with_long_import_path. adapter_ids,
4136+ vec![ CommandAdapterId :: CapnpCompile ]
4137+ ) ;
4138+ assert_eq ! ( capnp_with_long_import_path. filtered_output_count, 1 ) ;
4139+ assert_path_inputs (
4140+ & capnp_with_long_import_path,
4141+ & [ cwd. path ( ) . join ( "schemas" ) , cwd. path ( ) . join ( "schema.capnp" ) ] ,
4142+ ) ;
40524143 }
40534144
40544145 #[ test]
0 commit comments