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 let generate_output = match output_type with | "csv" -> Fixture.csv_of_generated_fixtures | "json" -> Fixture.json_of_generated_fixtures | _ -> failwith "Unsupported output type, supported types are: json, csv" in match result with | Some ast -> Ast_types.compile ast |> List.iter (fun (name, file) -> let result = generate_output 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) (* TODO: Support option to set output folder *) 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)