Created
March 11, 2019 22:24
-
-
Save actionshrimp/d8d20964813127d0d29ae5683660e774 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cat test.ml | |
type params = { | |
username: string; | |
(** Your Github username *) | |
api_key: string; | |
(** Your Github API key *) | |
command: string; [@pos 0] [@docv "CMD"] | |
(** The Github API command to run *) | |
dry_run: bool; | |
(** Don't really run this command *) | |
time_to_wait: float; [@default 0.] | |
(** Just an example of another type *) | |
} [@@deriving cmdliner,show] | |
$ ocamlfind ocamlc -dsource -linkall -linkpkg -package ppx_deriving,ppx_deriving.show,ppx_deriving.runtime,ppx_deriving_cmdliner test.ml | |
type params = | |
{ | |
username: string [@ocaml.doc " Your Github username "]; | |
api_key: string [@ocaml.doc " Your Github API key "]; | |
command: string | |
[@pos 0][@docv "CMD"][@ocaml.doc " The Github API command to run "]; | |
dry_run: bool [@ocaml.doc " Don't really run this command "]; | |
time_to_wait: float | |
[@default 0.][@ocaml.doc " Just an example of another type "]}[@@deriving | |
(cmdliner, | |
show)] | |
let rec (params_cmdliner_term : unit -> params Cmdliner.Term.t) = | |
((let open! Ppx_deriving_cmdliner_runtime in | |
fun () -> | |
Cmdliner.Term.app | |
(Cmdliner.Term.app | |
(Cmdliner.Term.app | |
(Cmdliner.Term.app | |
(Cmdliner.Term.app | |
(Cmdliner.Term.const | |
(fun time_to_wait -> | |
fun dry_run -> | |
fun command -> | |
fun api_key -> | |
fun username -> | |
{ | |
username; | |
api_key; | |
command; | |
dry_run; | |
time_to_wait | |
})) | |
(let open Cmdliner.Arg in | |
value & | |
((Cmdliner.Arg.opt Cmdliner.Arg.float 0.) & | |
(info ?env:None ?docs:None | |
?doc:(Some "Just an example of another type") | |
~docv:"FLOAT" ["time-to-wait"])))) | |
(let open Cmdliner.Arg in | |
value & | |
(flag & | |
(info ?env:None ?docs:None | |
?doc:(Some "Don't really run this command") | |
~docv:"BOOL" ["dry-run"])))) | |
(let open Cmdliner.Arg in | |
required & | |
(((Cmdliner.Arg.pos 0) (some Cmdliner.Arg.string) None) | |
& | |
(info ?env:None ?docs:None | |
?doc:(Some "The Github API command to run") | |
~docv:"CMD" [])))) | |
(let open Cmdliner.Arg in | |
required & | |
((Cmdliner.Arg.opt (some Cmdliner.Arg.string) None) & | |
(info ?env:None ?docs:None | |
?doc:(Some "Your Github API key") ~docv:"STRING" | |
["api-key"])))) | |
(let open Cmdliner.Arg in | |
required & | |
((Cmdliner.Arg.opt (some Cmdliner.Arg.string) None) & | |
(info ?env:None ?docs:None | |
?doc:(Some "Your Github username") ~docv:"STRING" | |
["username"])))) | |
[@ocaml.warning "-A"]) | |
let rec (pp_params : Format.formatter -> params -> Ppx_deriving_runtime.unit) | |
= | |
((let open! Ppx_deriving_runtime in | |
fun fmt -> | |
fun x -> | |
Format.fprintf fmt "@[<2>{ "; | |
(((((Format.fprintf fmt "@[%s =@ " "Test.username"; | |
(Format.fprintf fmt "%S") x.username; | |
Format.fprintf fmt "@]"); | |
Format.fprintf fmt ";@ "; | |
Format.fprintf fmt "@[%s =@ " "api_key"; | |
(Format.fprintf fmt "%S") x.api_key; | |
Format.fprintf fmt "@]"); | |
Format.fprintf fmt ";@ "; | |
Format.fprintf fmt "@[%s =@ " "command"; | |
(Format.fprintf fmt "%S") x.command; | |
Format.fprintf fmt "@]"); | |
Format.fprintf fmt ";@ "; | |
Format.fprintf fmt "@[%s =@ " "dry_run"; | |
(Format.fprintf fmt "%B") x.dry_run; | |
Format.fprintf fmt "@]"); | |
Format.fprintf fmt ";@ "; | |
Format.fprintf fmt "@[%s =@ " "time_to_wait"; | |
(Format.fprintf fmt "%F") x.time_to_wait; | |
Format.fprintf fmt "@]"); | |
Format.fprintf fmt "@ }@]") | |
[@ocaml.warning "-A"]) | |
and show_params : params -> Ppx_deriving_runtime.string = | |
fun x -> Format.asprintf "%a" pp_params x |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment