X-Git-Url: http://git.nguyen.vg/gitweb/?p=tatoo.git;a=blobdiff_plain;f=src%2Foptions.ml;h=70c2b4dbea74155285a67220f7e8800e5f77f364;hp=61f03966a7bfbf8851df3062588d89d904bbc26b;hb=398ce5dca1bee23f5137a3eba21df17d7aaaf1fa;hpb=88375a854dab33de2193a7da5be652ae50f2ca64 diff --git a/src/options.ml b/src/options.ml index 61f0396..70c2b4d 100644 --- a/src/options.ml +++ b/src/options.ml @@ -1,39 +1,28 @@ open Arg let count = ref false -let input_file = ref "" +let input_file : string option ref = ref None let output_file : string option ref = ref None let query = ref "" let stats = ref false +let set_string_option r s = r := Some s + let specs = align [ "-c", Set count, " write the number of results only"; "--count", Set count, " "; "-s", Set stats, " display timing and various statistics"; "--stats", Set stats, " "; + "-d", String (set_string_option input_file), " specify the input document file [default stdin]"; + "--doc", String (set_string_option input_file), " "; + "-o", String (set_string_option output_file), " specify the output file [default stdout]"; + "--out", String (set_string_option output_file), " "; ] -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_msg = Printf.sprintf "usage: %s [options] query" Sys.argv.(0) 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") - + parse specs (fun q -> query := q) usage_msg