From 2e9e7a38f1c448c8eae389fd218e77ba230cde2a Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Mon, 20 Jun 2022 08:02:41 +0200 Subject: [PATCH] Beautify --- bin/Extract.ml | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/bin/Extract.ml b/bin/Extract.ml index fba472e..496bb35 100644 --- a/bin/Extract.ml +++ b/bin/Extract.ml @@ -1,10 +1,10 @@ open Lib -let extract ~duplicatesAllowed paths = +let extract ~duplicatesAllowed ~paths = try let messages = Extractor.extract ~duplicatesAllowed paths in - `List (messages |> List.map Message.toJson) - |> Yojson.Basic.pretty_to_channel stdout; + let json = `List (messages |> List.map Message.toJson) in + json |> Yojson.Basic.pretty_to_channel stdout; print_newline () with | Extractor.PathNotFound path -> @@ -21,19 +21,20 @@ let extract ~duplicatesAllowed paths = Printf.eprintf "Unexpected error: %s\n" (Printexc.to_string exn); exit 10 -type options = {showVersion: bool; paths: string list; duplicatesAllowed: bool} +type options = { + mutable showVersion: bool; + mutable paths: string list; + mutable duplicatesAllowed: bool; +} let run () = - let options = - ref {showVersion = false; paths = []; duplicatesAllowed = false} - in + let options = {showVersion = false; paths = []; duplicatesAllowed = false} in let processInputFilename filename = - options := {!options with paths = filename :: !options.paths} - in - let allowDuplicates () = - options := {!options with duplicatesAllowed = true} + options.paths <- filename :: options.paths in - let showVersion () = options := {!options with showVersion = true} in + let allowDuplicates () = options.duplicatesAllowed <- true in + let showVersion () = options.showVersion <- true in + let args = [ ("-v", Arg.Unit showVersion, "shows the program version"); @@ -43,11 +44,13 @@ let run () = are identical as well" ); ] in + let usage = "Usage: " ^ Sys.argv.(0) ^ " [path...]" in Arg.parse args processInputFilename usage; - match !options with + + match options with | {showVersion = true} -> print_endline Version.version | {paths = []} -> Arg.usage args usage - | {paths; duplicatesAllowed} -> extract ~duplicatesAllowed paths + | {paths; duplicatesAllowed} -> extract ~duplicatesAllowed ~paths let () = run ()