Change command line options:
[tatoo.git] / src / options.ml
index 61f0396..70c2b4d 100644 (file)
@@ -1,39 +1,28 @@
 open Arg
 
 let count = ref false
 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 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, " ";
 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 () =
 
 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