diff options
author | Marc Coquand <marc@mccd.space> | 2023-12-26 09:02:53 -0600 |
---|---|---|
committer | Marc Coquand <marc@mccd.space> | 2023-12-26 09:57:19 -0600 |
commit | cb124a87d8ed1a309b00c9163cde2911ee029251 (patch) | |
tree | ebb46550ef6236c66ddde5894128ca2e492229df /bin | |
parent | 5036848184a912a857c4c1e76ef02985295855eb (diff) | |
download | fixgen-cb124a87d8ed1a309b00c9163cde2911ee029251.tar.gz fixgen-cb124a87d8ed1a309b00c9163cde2911ee029251.tar.bz2 fixgen-cb124a87d8ed1a309b00c9163cde2911ee029251.zip |
Add cmdliner
Diffstat (limited to '')
-rw-r--r-- | bin/dune | 1 | ||||
-rw-r--r-- | bin/main.ml | 39 |
2 files changed, 30 insertions, 10 deletions
@@ -2,5 +2,6 @@ (public_name fixgen) (name main) (libraries + cmdliner fixgen) ) diff --git a/bin/main.ml b/bin/main.ml index 6942382..c964c5e 100644 --- a/bin/main.ml +++ b/bin/main.ml @@ -1,4 +1,5 @@ open Fixgen +open Cmdliner let parse (s : string) = let lexbuf = Lexing.from_string s in @@ -6,13 +7,31 @@ let parse (s : string) = ast -let () = - let result = parse "user: id uuidv4, uh uuidv4\npurchases: id uuidv4, pid user.id" in - match result with - | Some ast -> - Ast_types.compile ast ~amount:4 - |> 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 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 ~amount:4 + |> 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) |