support @name as shortcut for [sqlgg] name=...
[sqlgg.git] / sqlgg.ml
blobe3aa46af83e47b30122be8c61153366613aa1e60
1 (** command-line *)
3 open Printf
4 open Operators
6 module Cxx = Gen.Make(Gen_cxx)
7 module Caml = Gen.Make(Gen_caml)
9 let generate = ref Cxx.process
11 let set_out s =
12 generate :=
13 match s with
14 | "cxx" -> Cxx.process
15 | "caml" -> Caml.process
16 | _ -> failwith (sprintf "Unknown output language: %s" s)
18 let work =
19 let f s = s >> Main.parse_sql >> !generate in
20 function
21 | "-" -> f (Std.input_all stdin)
22 | filename -> Main.with_file filename f
24 let usage_msg =
25 let s1 = sprintf "SQL Guided (code) Generator ver. %s\n" Config.version in
26 let s2 = sprintf "Usage: %s <options> <file.sql>\n" (Filename.basename Sys.executable_name) in
27 let s3 = "Options are:" in
28 s1 ^ s2 ^ s3
30 let show_version () = print_endline Config.version
32 let main () =
33 let args =
35 "-version", Arg.Unit show_version, " Show version";
36 "-gen", Arg.String set_out, "cxx|caml Set output language";
37 "-test", Arg.Unit Test.run, " Run unit tests";
40 Arg.parse (Arg.align args) work usage_msg
42 let _ = Printexc.print main ()