diff --git a/lib/app/configuration/command_configuration.ml b/lib/app/configuration/command_configuration.ml index 20717ab..bab042b 100644 --- a/lib/app/configuration/command_configuration.ml +++ b/lib/app/configuration/command_configuration.ml @@ -692,11 +692,14 @@ let ripgrep_file_filters specifications args : string list = in let result = Ripgrep.run ~pattern:regex ~args in match result with - | Ok result -> + | Ok Some result -> if debug then Format.printf "Ripgrep result: %s@." @@ String.concat ~sep:"\n" result; result + | Ok None -> + if debug then Format.printf "No ripgrep results, no files to process. Exiting 0."; + exit 0 | Error e -> - Format.eprintf "%s@." (Error.to_string_hum e); + if debug then Format.eprintf "%s@." (Error.to_string_hum e); exit 1 let create diff --git a/lib/app/configuration/ripgrep.ml b/lib/app/configuration/ripgrep.ml index 2b5f108..2804de1 100644 --- a/lib/app/configuration/ripgrep.ml +++ b/lib/app/configuration/ripgrep.ml @@ -21,7 +21,8 @@ let run ~pattern ~args = Lwt_process.with_process_in lwt_command (fun proc -> recv proc >>= fun result -> proc#status >>= function + | WEXITED v when v = 1 -> return (Ok None) (* no matches *) | WEXITED v when v <> 0 -> return @@ Or_error.errorf "Error executing rg, exit status %d." v - | _ -> return (Ok (String.split ~on:'\n' result |> List.filter ~f:(String.(<>) "")))) + | _ -> return (Ok (Some (String.split ~on:'\n' result |> List.filter ~f:(String.(<>) ""))))) in try Lwt_main.run (f ()) with Sys.Break -> exit 0 diff --git a/lib/app/configuration/ripgrep.mli b/lib/app/configuration/ripgrep.mli index 242cd07..3db6c04 100644 --- a/lib/app/configuration/ripgrep.mli +++ b/lib/app/configuration/ripgrep.mli @@ -3,4 +3,4 @@ open Core (* [run pattern args] accepts a [pattern] and list of extra ripgrep-compatible arguments [args], for example, ["-g"; "*.go"; "-g"; "*.ts"]. Returns a list of files if the commands succeeds. *) -val run : pattern:string -> args:string list -> string list Or_error.t +val run : pattern:string -> args:string list -> string list option Or_error.t