Skip to content

Beautify #84

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 20, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 17 additions & 14 deletions bin/Extract.ml
Original file line number Diff line number Diff line change
@@ -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 ->
Expand All @@ -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");
Expand All @@ -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 ()