X-Git-Url: http://git.nguyen.vg/gitweb/?p=tatoo.git;a=blobdiff_plain;f=src%2Foptions.ml;fp=src%2Foptions.ml;h=142b709491d3026319bdfcad2d9c2d0465d7ff53;hp=0000000000000000000000000000000000000000;hb=5b5dcd45cf86701ccfe917c1d6ad73b83bb523c3;hpb=f71defc62c481fe8a3a161d904790f3ca117a8cb diff --git a/src/options.ml b/src/options.ml new file mode 100644 index 0000000..142b709 --- /dev/null +++ b/src/options.ml @@ -0,0 +1,39 @@ +open Arg + +let count = ref false +let input_file = ref "" +let output_file : string option ref = ref None +let query = ref "" +let stats = ref false + +let specs = align [ + "-c", Set count, ""; + "--count", Set count, " write the number of results only"; + "-s", Set stats, ""; + "--stats", Set stats, " display timing and various statistics"; +] + +let usage_msg = Printf.sprintf "usage: %s [options] input.xml query [output.xml]" Sys.argv.(0) + +let get_anon, anon_arg = + let args = ref [] in + (fun () -> !args), + (fun s -> args := s::!args) + +let usage () = usage specs usage_msg + +let parse () = + parse specs anon_arg usage_msg; + match List.rev (get_anon ()) with + input :: q :: maybe_output -> + input_file := input; + query := q; + begin + match maybe_output with + [] -> () + | [ output ] -> output_file := Some output + | _ -> raise (Arg.Bad "too many arguments") + end + | [] | [ _ ] -> raise (Arg.Bad "not enough arguments") + +