@@ -192,7 +192,7 @@ enum Command {
192192 /// Pattern to search for (regex or fixed string)
193193 pattern : String ,
194194 /// Optional file paths or globs to filter results
195- #[ arg( value_name = "PATH" , allow_hyphen_values = true ) ]
195+ #[ arg( value_name = "PATH" ) ]
196196 paths : Vec < String > ,
197197 /// Treat pattern as fixed string, not regex
198198 #[ arg( short = 'F' , long) ]
@@ -388,22 +388,6 @@ fn reject_grep_limit(_value: &str) -> Result<String, String> {
388388 )
389389}
390390
391- fn reject_unsupported_grep_flags ( command : & Command ) -> anyhow:: Result < ( ) > {
392- if let Command :: Grep { paths, .. } = command
393- && let Some ( flag) = paths. iter ( ) . find ( |path| path. starts_with ( '-' ) )
394- {
395- if flag == "--limit" {
396- anyhow:: bail!(
397- "gcode grep is indexed search; --limit is unsupported. Use -m/--max-count, or run raw `rg` for filesystem grep."
398- ) ;
399- }
400- anyhow:: bail!(
401- "gcode grep is indexed search; unsupported grep/rg flag `{flag}`. Use raw `rg` for filesystem grep."
402- ) ;
403- }
404- Ok ( ( ) )
405- }
406-
407391fn dispatch_early_command < F > ( cli : & Cli , setup_runner : F ) -> anyhow:: Result < bool >
408392where
409393 F : FnOnce ( setup:: StandaloneSetupRequest , output:: Format , bool ) -> anyhow:: Result < ( ) > ,
@@ -500,7 +484,6 @@ fn run() -> anyhow::Result<()> {
500484 if dispatch_early_command ( & cli, commands:: setup:: run) ? {
501485 return Ok ( ( ) ) ;
502486 }
503- reject_unsupported_grep_flags ( & cli. command ) ?;
504487
505488 let ctx = config:: Context :: resolve ( cli. project . as_deref ( ) , cli. quiet ) ?;
506489
@@ -1439,24 +1422,56 @@ mod tests {
14391422 let cli = Cli :: try_parse_from ( [ "gcode" , "grep" , "needle" , "-m" , "5" , "src" ] )
14401423 . expect ( "grep with -m parses" ) ;
14411424 match cli. command {
1442- Command :: Grep { max_count, .. } => assert_eq ! ( max_count, Some ( 5 ) ) ,
1425+ Command :: Grep {
1426+ paths, max_count, ..
1427+ } => {
1428+ assert_eq ! ( paths, vec![ "src" ] ) ;
1429+ assert_eq ! ( max_count, Some ( 5 ) ) ;
1430+ }
14431431 _ => panic ! ( "expected grep command" ) ,
14441432 }
14451433
14461434 let cli = Cli :: try_parse_from ( [ "gcode" , "grep" , "needle" , "--max-count" , "5" , "src" ] )
14471435 . expect ( "grep with --max-count parses" ) ;
14481436 match cli. command {
1449- Command :: Grep { max_count, .. } => assert_eq ! ( max_count, Some ( 5 ) ) ,
1437+ Command :: Grep {
1438+ paths, max_count, ..
1439+ } => {
1440+ assert_eq ! ( paths, vec![ "src" ] ) ;
1441+ assert_eq ! ( max_count, Some ( 5 ) ) ;
1442+ }
1443+ _ => panic ! ( "expected grep command" ) ,
1444+ }
1445+
1446+ let cli = Cli :: try_parse_from ( [ "gcode" , "grep" , "needle" , "src" , "-m" , "5" ] )
1447+ . expect ( "grep with -m after path parses" ) ;
1448+ match cli. command {
1449+ Command :: Grep {
1450+ paths, max_count, ..
1451+ } => {
1452+ assert_eq ! ( paths, vec![ "src" ] ) ;
1453+ assert_eq ! ( max_count, Some ( 5 ) ) ;
1454+ }
1455+ _ => panic ! ( "expected grep command" ) ,
1456+ }
1457+
1458+ let cli = Cli :: try_parse_from ( [ "gcode" , "grep" , "needle" , "src" , "--max-count" , "5" ] )
1459+ . expect ( "grep with --max-count after path parses" ) ;
1460+ match cli. command {
1461+ Command :: Grep {
1462+ paths, max_count, ..
1463+ } => {
1464+ assert_eq ! ( paths, vec![ "src" ] ) ;
1465+ assert_eq ! ( max_count, Some ( 5 ) ) ;
1466+ }
14501467 _ => panic ! ( "expected grep command" ) ,
14511468 }
14521469 }
14531470
14541471 #[ test]
14551472 fn parse_grep_rejects_limit ( ) {
1456- let cli = Cli :: try_parse_from ( [ "gcode" , "grep" , "needle" , "src" , "--limit" , "5" ] )
1457- . expect ( "--limit is captured for custom rejection" ) ;
1458- let err =
1459- reject_unsupported_grep_flags ( & cli. command ) . expect_err ( "--limit should be rejected" ) ;
1473+ let err = Cli :: try_parse_from ( [ "gcode" , "grep" , "needle" , "src" , "--limit" , "5" ] )
1474+ . expect_err ( "--limit should be rejected" ) ;
14601475 assert ! (
14611476 err. to_string( ) . contains( "gcode grep is indexed search" ) ,
14621477 "unexpected error: {err}"
@@ -1469,18 +1484,12 @@ mod tests {
14691484
14701485 #[ test]
14711486 fn parse_grep_unsupported_flag_fails_before_context_resolution ( ) {
1472- let cli = Cli :: try_parse_from ( [ "gcode" , "grep" , "needle" , "--files-with-matches" ] )
1473- . expect ( "unsupported grep flag is captured for custom rejection" ) ;
1474-
1475- let err = reject_unsupported_grep_flags ( & cli. command )
1487+ let err = Cli :: try_parse_from ( [ "gcode" , "grep" , "needle" , "--files-with-matches" ] )
14761488 . expect_err ( "unsupported grep flag should fail" ) ;
14771489
14781490 assert ! (
1479- err. to_string( ) . contains( "gcode grep is indexed search" ) ,
1480- "unexpected error: {err}"
1481- ) ;
1482- assert ! (
1483- err. to_string( ) . contains( "raw `rg`" ) ,
1491+ err. to_string( )
1492+ . contains( "unexpected argument '--files-with-matches'" ) ,
14841493 "unexpected error: {err}"
14851494 ) ;
14861495 }
0 commit comments