Skip to content

Commit 94bd887

Browse files
fhammerschmidtcknitt
authored andcommitted
Add verbose flag
1 parent 6bebd1e commit 94bd887

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

bin/Extract.ml

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
open Lib
22

3-
let extract ~duplicatesAllowed ~paths =
3+
let extract ~duplicatesAllowed ~verbose ~paths =
44
try
5-
let messages = Extractor.extract ~duplicatesAllowed paths in
5+
let messages = Extractor.extract ~duplicatesAllowed ~verbose paths in
66
let json = `List (messages |> List.map Message.toJson) in
77
json |> Yojson.Basic.pretty_to_channel stdout;
88
print_newline ()
@@ -25,19 +25,31 @@ type options = {
2525
mutable showVersion: bool;
2626
mutable paths: string list;
2727
mutable duplicatesAllowed: bool;
28+
mutable verbose: bool;
2829
}
2930

3031
let run () =
31-
let options = {showVersion = false; paths = []; duplicatesAllowed = false} in
32+
let options =
33+
{
34+
showVersion = false;
35+
paths = [];
36+
duplicatesAllowed = false;
37+
verbose = false;
38+
}
39+
in
3240
let processInputFilename filename =
3341
options.paths <- filename :: options.paths
3442
in
3543
let allowDuplicates () = options.duplicatesAllowed <- true in
3644
let showVersion () = options.showVersion <- true in
45+
let verbose () = options.verbose <- true in
3746

3847
let args =
3948
[
4049
("-v", Arg.Unit showVersion, "shows the program version");
50+
( "--verbose",
51+
Arg.Unit verbose,
52+
"log some information like the current processed file path" );
4153
( "--allow-duplicates",
4254
Arg.Unit allowDuplicates,
4355
"allows messages with identical `id` props if `defaultMessage` props \
@@ -51,6 +63,7 @@ let run () =
5163
match options with
5264
| {showVersion = true} -> print_endline Version.version
5365
| {paths = []} -> Arg.usage args usage
54-
| {paths; duplicatesAllowed} -> extract ~duplicatesAllowed ~paths
66+
| {paths; duplicatesAllowed; verbose} ->
67+
extract ~duplicatesAllowed ~verbose ~paths
5568

5669
let () = run ()

lib/Extractor.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ exception PathNotFound of string
22
exception DuplicateMessageId of string
33
exception DefaultMessageNotMatching of string
44

5-
let extract ?(duplicatesAllowed = false) paths =
5+
let extract ?(duplicatesAllowed = false) ?(verbose = false) paths =
66
let messages = ref StringMap.empty in
77
let iterator =
88
ExtractionIterator.getIterator (fun message ->
@@ -21,6 +21,7 @@ let extract ?(duplicatesAllowed = false) paths =
2121
in
2222
let extractMessages ast = iterator.structure iterator ast in
2323
let processFile path =
24+
if verbose then Printf.eprintf "Processing file: %s\n%!" path;
2425
let channel = open_in_bin path in
2526
let src = really_input_string channel (in_channel_length channel) in
2627
close_in channel;

0 commit comments

Comments
 (0)