diff options
author | Chimrod <> | 2023-10-03 08:23:59 +0200 |
---|---|---|
committer | Chimrod <> | 2023-10-03 08:23:59 +0200 |
commit | f21a7b0552f65de232ab75bdd3172c6c182292b1 (patch) | |
tree | 223ab29f222699c47cc9eb3e644bd61ba8af53c2 /bin/args.ml | |
parent | b7964befd039c41c63e00ef323f9eb49061c144c (diff) |
In windows, do not ask the user before terminating
Diffstat (limited to 'bin/args.ml')
-rw-r--r-- | bin/args.ml | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/bin/args.ml b/bin/args.ml new file mode 100644 index 0000000..e4e892c --- /dev/null +++ b/bin/args.ml @@ -0,0 +1,58 @@ +module Report = Qsp_syntax.Report + +let input_files = ref [] +let usage = "qsp_parser input_file" +let anon_fun filename = input_files := filename :: !input_files +let level_value = ref None +let reset_line = ref false +let interractive = ref true + +type filters = { level : Report.level option } + +type t = { reset_line : bool; filters : filters; interractive : bool } +(** All the arguments given from the command line *) + +let level : string -> unit = + fun str_level -> + match Report.level_of_string str_level with + | Ok level_ -> level_value := Some level_ + | Error e -> + print_endline e; + exit 1 + +let speclist = + let common_arguments = + [ + ( "--version", + Arg.Unit + (fun () -> + Printf.printf "Version %s\n" Tools.Git_hash.revision; + exit 0), + "\tDisplay the version of the application and exit" ); + ("--level", Arg.String level, "\tMessage level [debug, warn, error]"); + ( "--global", + Arg.Set reset_line, + "\tEach line is refered from the begining of the file and not the \ + location" ); + ] + and windows_arguments = + match Sys.os_type with + | "Win32" -> + [ + ( "--no-prompt", + Arg.Clear interractive, + "\tDo not ask the user to press enter after processing the source" + ); + ] + | _ -> + interractive := false; + [] + in + common_arguments @ windows_arguments + +let parse : unit -> string list * t = + fun () -> + let () = Arg.parse (Arg.align speclist) anon_fun usage in + let filters = { level = !level_value } in + ( !input_files, + { reset_line = !reset_line; filters; interractive = !interractive } ) |