@@ -25,10 +25,7 @@ module Exporter = struct
25
25
| _ ->
26
26
()
27
27
28
- (* * Export traces from file system to a remote endpoint. *)
29
- let export erase src dst =
30
- let dst = Uri. of_string dst in
31
- let submit_json = submit_json dst in
28
+ let iter_src src f =
32
29
let rec export_file = function
33
30
| path when Sys. is_directory path ->
34
31
(* Recursively export trace files. *)
@@ -38,7 +35,7 @@ module Exporter = struct
38
35
(* Decompress compressed trace file and submit each line iteratively *)
39
36
let args = [|" zstdcat" ; path|] in
40
37
let ic = Unix. open_process_args_in args.(0 ) args in
41
- Unixext. lines_iter submit_json ic ;
38
+ Unixext. lines_iter f ic ;
42
39
match Unix. close_process_in ic with
43
40
| Unix. WEXITED 0 ->
44
41
()
@@ -47,15 +44,25 @@ module Exporter = struct
47
44
)
48
45
| path when Filename. check_suffix path " .ndjson" ->
49
46
(* Submit traces line by line. *)
50
- Unixext. readfile_line submit_json path
47
+ Unixext. readfile_line f path
51
48
| path ->
52
49
(* Assume any other extension is a valid JSON file. *)
53
50
let json = Unixext. string_of_file path in
54
- submit_json json
51
+ f json
55
52
in
56
- export_file src ;
53
+ export_file src
54
+
55
+ (* * Export traces from file system to a remote endpoint. *)
56
+ let export erase src dst =
57
+ let dst = Uri. of_string dst in
58
+ let submit_json = submit_json dst in
59
+ iter_src src submit_json;
57
60
if erase then
58
61
Unixext. rm_rec ~rm_top: true src
62
+
63
+ let pretty_print src =
64
+ iter_src src @@ fun line ->
65
+ line |> Yojson.Safe. from_string |> Yojson.Safe. pretty_to_channel ~std: true stdout
59
66
end
60
67
61
68
module Cli = struct
@@ -83,6 +90,11 @@ module Cli = struct
83
90
let doc = " copy a trace to an endpoint and erase it afterwards" in
84
91
Cmd. (v (info " mv" ~doc ) term)
85
92
93
+ let pp_cmd =
94
+ let term = Term. (const Exporter. pretty_print $ src) in
95
+ let doc = " Pretty print NDJSON traces" in
96
+ Cmd. (v (info " pp" ~doc ) term)
97
+
86
98
let xs_trace_cmd =
87
99
let man =
88
100
[
@@ -94,7 +106,7 @@ module Cli = struct
94
106
let doc = " utility for working with local trace files" in
95
107
Cmd. info " xs-trace" ~doc ~version: " 0.1" ~man
96
108
in
97
- Cmd. group desc [cp_cmd; mv_cmd]
109
+ Cmd. group desc [cp_cmd; mv_cmd; pp_cmd ]
98
110
99
111
let main () = Cmd. eval xs_trace_cmd
100
112
end
0 commit comments