@@ -623,39 +623,41 @@ fn execute_json_operation(op: &JsonOperation) -> JsonOperationResult {
623623 // source = directory to search
624624 // content = glob pattern (e.g., "*.rs")
625625 // destination = output file path
626- if let ( Some ( dir) , Some ( pattern) , Some ( dest) ) = ( & op. source , & op. content , & op. destination ) {
627- let entries = list_directory ( dir) ?;
628-
629- // Simple glob matching: *.ext means ends with .ext
630- let matching: Vec < _ > = entries. iter ( )
631- . filter ( |name| {
632- if pattern. starts_with ( "*." ) {
633- let ext = & pattern[ 1 ..] ; // Remove *
634- name. ends_with ( ext)
635- } else {
636- name == pattern
637- }
638- } )
639- . collect ( ) ;
640-
641- if matching. is_empty ( ) {
642- return Err ( anyhow:: anyhow!( "No files matching '{}' found in {}" , pattern, dir) ) ;
643- }
644-
645- // Copy the first match
646- let source_path = format ! ( "{}/{}" , dir, matching[ 0 ] ) ;
647- copy_file ( & source_path, dest) ?;
648-
649- let message = if matching. len ( ) > 1 {
650- format ! ( "Copied first match '{}' (found {} total)" , matching[ 0 ] , matching. len( ) )
626+ ( || {
627+ if let ( Some ( dir) , Some ( pattern) , Some ( dest) ) = ( & op. source , & op. content , & op. destination ) {
628+ let entries = list_directory ( dir) ?;
629+
630+ // Simple glob matching: *.ext means ends with .ext
631+ let matching: Vec < _ > = entries. iter ( )
632+ . filter ( |name| {
633+ if pattern. starts_with ( "*." ) {
634+ let ext = & pattern[ 1 ..] ; // Remove *
635+ name. ends_with ( ext)
636+ } else {
637+ name. as_str ( ) == pattern
638+ }
639+ } )
640+ . collect ( ) ;
641+
642+ if matching. is_empty ( ) {
643+ return Err ( anyhow:: anyhow!( "No files matching '{}' found in {}" , pattern, dir) ) ;
644+ }
645+
646+ // Copy the first match
647+ let source_path = format ! ( "{}/{}" , dir, matching[ 0 ] ) ;
648+ copy_file ( & source_path, dest) ?;
649+
650+ let message = if matching. len ( ) > 1 {
651+ format ! ( "Copied first match '{}' (found {} total)" , matching[ 0 ] , matching. len( ) )
652+ } else {
653+ format ! ( "Copied '{}'" , matching[ 0 ] )
654+ } ;
655+
656+ Ok ( Some ( message) )
651657 } else {
652- format ! ( "Copied '{}'" , matching[ 0 ] )
653- } ;
654-
655- Ok ( Some ( message) )
656- } else {
657- Err ( anyhow:: anyhow!( "copy_first_matching requires source (dir), content (pattern), and destination" ) )
658- }
658+ Err ( anyhow:: anyhow!( "copy_first_matching requires source (dir), content (pattern), and destination" ) )
659+ }
660+ } ) ( )
659661 }
660662 "path_exists" => {
661663 if let Some ( source) = & op. source {
0 commit comments