1
1
open Lib
2
2
3
- let extract ~duplicatesAllowed paths =
3
+ let extract ~duplicatesAllowed ~ paths =
4
4
try
5
5
let messages = Extractor. extract ~duplicates Allowed 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;
8
8
print_newline ()
9
9
with
10
10
| Extractor. PathNotFound path ->
@@ -21,19 +21,20 @@ let extract ~duplicatesAllowed paths =
21
21
Printf. eprintf " Unexpected error: %s\n " (Printexc. to_string exn );
22
22
exit 10
23
23
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
+ }
25
29
26
30
let run () =
27
- let options =
28
- ref {showVersion = false ; paths = [] ; duplicatesAllowed = false }
29
- in
31
+ let options = {showVersion = false ; paths = [] ; duplicatesAllowed = false } in
30
32
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
35
34
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
+
37
38
let args =
38
39
[
39
40
(" -v" , Arg. Unit showVersion, " shows the program version" );
@@ -43,11 +44,13 @@ let run () =
43
44
are identical as well" );
44
45
]
45
46
in
47
+
46
48
let usage = " Usage: " ^ Sys. argv.(0 ) ^ " [path...]" in
47
49
Arg. parse args processInputFilename usage;
48
- match ! options with
50
+
51
+ match options with
49
52
| {showVersion = true } -> print_endline Version. version
50
53
| {paths = [] } -> Arg. usage args usage
51
- | {paths; duplicatesAllowed} -> extract ~duplicates Allowed paths
54
+ | {paths; duplicatesAllowed} -> extract ~duplicates Allowed ~ paths
52
55
53
56
let () = run ()
0 commit comments