Add a clean logger infrastructure.
[tatoo.git] / src / options.ml
1 open Arg
2
3 let count = ref false
4 let input_file = ref ""
5 let output_file : string option ref = ref None
6 let query = ref ""
7 let stats = ref false
8
9 let specs = align [
10   "-c", Set count, " write the number of results only";
11   "--count", Set count, " ";
12   "-s", Set stats, " display timing and various statistics";
13   "--stats", Set stats, " ";
14 ]
15
16 let usage_msg = Printf.sprintf "usage: %s [options] input.xml query [output.xml]" Sys.argv.(0)
17
18 let get_anon, anon_arg =
19   let args = ref []  in
20   (fun () -> !args),
21   (fun s -> args := s::!args)
22
23 let usage () = usage specs usage_msg
24
25 let parse () =
26   parse specs anon_arg usage_msg;
27   match List.rev (get_anon ()) with
28      input :: q :: maybe_output ->
29        input_file := input;
30        query := q;
31        begin
32          match maybe_output with
33            [] -> ()
34          | [ output ] -> output_file := Some output
35          | _ -> raise (Arg.Bad "too many arguments")
36        end
37   | [] | [ _ ] -> raise (Arg.Bad "not enough arguments")
38
39