aboutsummaryrefslogtreecommitdiff
path: root/bin/main.ml
blob: 29f354fb0405336483a11f3420fcfaa3d84fd4c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
open Fixgen
open Cmdliner

let parse (s : string) =
  let lexbuf = Lexing.from_string s in
  let ast = Parser.prog Lexer.read lexbuf in
  ast


let fixgen content output_type () =
  let result = parse content in
  if output_type != "csv"
  then print_endline "Only csv output is supported"
  else (
    match result with
    | Some ast ->
      Ast_types.compile ast
      |> List.iter (fun (name, file) ->
        let result = Fixture.csv_of_generated_fixtures file in
        print_endline ("FILE NAME: " ^ name);
        print_endline result)
    | None -> print_endline "error")


let file =
  let doc = "Fixgen content" in
  Arg.(required & pos 0 (some string) None & info [] ~docv:"PROGRAM" ~doc)


let output_type =
  let doc = "Set output file type, supported=csv" in
  Arg.(value & opt string "csv" & info [ "f"; "file-type" ] ~docv:"FILE TYPE" ~doc)


let fixgen_t = Term.(const fixgen $ file $ output_type $ const ())
let cmd = Cmd.v (Cmd.info "fixgen") fixgen_t
let () = exit (Cmd.eval cmd)