put no rg output behind debug flag

This commit is contained in:
Rijnard van Tonder 2021-05-12 12:24:22 -07:00
parent 55c793f48f
commit ed43b4fc63
3 changed files with 8 additions and 4 deletions

View File

@ -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

View File

@ -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

View File

@ -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