Skip to content

Commit

Permalink
Add verbose flag
Browse files Browse the repository at this point in the history
  • Loading branch information
fhammerschmidt committed Sep 1, 2023
1 parent 6bebd1e commit be3c7ec
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
21 changes: 17 additions & 4 deletions bin/Extract.ml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
open Lib

let extract ~duplicatesAllowed ~paths =
let extract ~duplicatesAllowed ~verbose ~paths =
try
let messages = Extractor.extract ~duplicatesAllowed paths in
let messages = Extractor.extract ~duplicatesAllowed ~verbose paths in
let json = `List (messages |> List.map Message.toJson) in
json |> Yojson.Basic.pretty_to_channel stdout;
print_newline ()
Expand All @@ -25,19 +25,31 @@ type options = {
mutable showVersion: bool;
mutable paths: string list;
mutable duplicatesAllowed: bool;
mutable verbose: bool;
}

let run () =
let options = {showVersion = false; paths = []; duplicatesAllowed = false} in
let options =
{
showVersion = false;
paths = [];
duplicatesAllowed = false;
verbose = false;
}
in
let processInputFilename filename =
options.paths <- filename :: options.paths
in
let allowDuplicates () = options.duplicatesAllowed <- true in
let showVersion () = options.showVersion <- true in
let verbose () = options.verbose <- true in

let args =
[
("-v", Arg.Unit showVersion, "shows the program version");
( "--verbose",
Arg.Unit verbose,
"log out some information like the current processed file path" );
( "--allow-duplicates",
Arg.Unit allowDuplicates,
"allows messages with identical `id` props if `defaultMessage` props \
Expand All @@ -51,6 +63,7 @@ let run () =
match options with
| {showVersion = true} -> print_endline Version.version
| {paths = []} -> Arg.usage args usage
| {paths; duplicatesAllowed} -> extract ~duplicatesAllowed ~paths
| {paths; duplicatesAllowed; verbose} ->
extract ~duplicatesAllowed ~verbose ~paths

let () = run ()
3 changes: 2 additions & 1 deletion lib/Extractor.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ exception PathNotFound of string
exception DuplicateMessageId of string
exception DefaultMessageNotMatching of string

let extract ?(duplicatesAllowed = false) paths =
let extract ?(duplicatesAllowed = false) ?(verbose = false) paths =
let messages = ref StringMap.empty in
let iterator =
ExtractionIterator.getIterator (fun message ->
Expand All @@ -21,6 +21,7 @@ let extract ?(duplicatesAllowed = false) paths =
in
let extractMessages ast = iterator.structure iterator ast in
let processFile path =
if verbose then Printf.eprintf "Processing file: %s\n%!" path;
let channel = open_in_bin path in
let src = really_input_string channel (in_channel_length channel) in
close_in channel;
Expand Down

0 comments on commit be3c7ec

Please sign in to comment.