aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorMarc Coquand <marc@mccd.space>2023-12-26 10:51:13 -0600
committerMarc Coquand <marc@mccd.space>2023-12-26 10:51:13 -0600
commitfc077e16adf2860af3d32a60cabd67f57bab0803 (patch)
treeb636d3a57f65c3fa8bf5cfd0aaaef044ba9e2948 /bin
parent2a664a47c73e232b6ff0d261833e2561d4abc4d0 (diff)
downloadfixgen-fc077e16adf2860af3d32a60cabd67f57bab0803.tar.gz
fixgen-fc077e16adf2860af3d32a60cabd67f57bab0803.tar.bz2
fixgen-fc077e16adf2860af3d32a60cabd67f57bab0803.zip
Support json output
Diffstat (limited to 'bin')
-rw-r--r--bin/main.ml27
1 files changed, 16 insertions, 11 deletions
diff --git a/bin/main.ml b/bin/main.ml
index 29f354f..d644133 100644
--- a/bin/main.ml
+++ b/bin/main.ml
@@ -9,17 +9,20 @@ let parse (s : string) =
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 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 =
@@ -27,6 +30,8 @@ let file =
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)