Skip to content

Commit d54689c

Browse files
authored
Beautify (#84)
1 parent 45d0e0a commit d54689c

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

bin/Extract.ml

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

3-
let extract ~duplicatesAllowed paths =
3+
let extract ~duplicatesAllowed ~paths =
44
try
55
let messages = Extractor.extract ~duplicatesAllowed paths in
6-
`List (messages |> List.map Message.toJson)
7-
|> Yojson.Basic.pretty_to_channel stdout;
6+
let json = `List (messages |> List.map Message.toJson) in
7+
json |> Yojson.Basic.pretty_to_channel stdout;
88
print_newline ()
99
with
1010
| Extractor.PathNotFound path ->
@@ -21,19 +21,20 @@ let extract ~duplicatesAllowed paths =
2121
Printf.eprintf "Unexpected error: %s\n" (Printexc.to_string exn);
2222
exit 10
2323

24-
type options = {showVersion: bool; paths: string list; duplicatesAllowed: bool}
24+
type options = {
25+
mutable showVersion: bool;
26+
mutable paths: string list;
27+
mutable duplicatesAllowed: bool;
28+
}
2529

2630
let run () =
27-
let options =
28-
ref {showVersion = false; paths = []; duplicatesAllowed = false}
29-
in
31+
let options = {showVersion = false; paths = []; duplicatesAllowed = false} in
3032
let processInputFilename filename =
31-
options := {!options with paths = filename :: !options.paths}
32-
in
33-
let allowDuplicates () =
34-
options := {!options with duplicatesAllowed = true}
33+
options.paths <- filename :: options.paths
3534
in
36-
let showVersion () = options := {!options with showVersion = true} in
35+
let allowDuplicates () = options.duplicatesAllowed <- true in
36+
let showVersion () = options.showVersion <- true in
37+
3738
let args =
3839
[
3940
("-v", Arg.Unit showVersion, "shows the program version");
@@ -43,11 +44,13 @@ let run () =
4344
are identical as well" );
4445
]
4546
in
47+
4648
let usage = "Usage: " ^ Sys.argv.(0) ^ " [path...]" in
4749
Arg.parse args processInputFilename usage;
48-
match !options with
50+
51+
match options with
4952
| {showVersion = true} -> print_endline Version.version
5053
| {paths = []} -> Arg.usage args usage
51-
| {paths; duplicatesAllowed} -> extract ~duplicatesAllowed paths
54+
| {paths; duplicatesAllowed} -> extract ~duplicatesAllowed ~paths
5255

5356
let () = run ()

0 commit comments

Comments
 (0)