{"id":19519463,"url":"https://github.com/hammerlab/ppx_deriving_cmdliner","last_synced_at":"2025-04-26T07:31:16.067Z","repository":{"id":18519622,"uuid":"84512356","full_name":"hammerlab/ppx_deriving_cmdliner","owner":"hammerlab","description":"Ppx_deriving plugin for generating command line interfaces from types (Cmdliner.Term.t)","archived":false,"fork":false,"pushed_at":"2023-09-12T19:57:57.000Z","size":65,"stargazers_count":97,"open_issues_count":13,"forks_count":12,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-04T09:44:37.751Z","etag":null,"topics":["cli","command-line-parser","ocaml","ppx","ppx-extension"],"latest_commit_sha":null,"homepage":"","language":"OCaml","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hammerlab.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-03-10T02:50:53.000Z","updated_at":"2025-01-24T17:07:08.000Z","dependencies_parsed_at":"2022-09-16T15:20:22.468Z","dependency_job_id":null,"html_url":"https://github.com/hammerlab/ppx_deriving_cmdliner","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hammerlab%2Fppx_deriving_cmdliner","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hammerlab%2Fppx_deriving_cmdliner/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hammerlab%2Fppx_deriving_cmdliner/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hammerlab%2Fppx_deriving_cmdliner/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hammerlab","download_url":"https://codeload.github.com/hammerlab/ppx_deriving_cmdliner/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250953416,"owners_count":21513334,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cli","command-line-parser","ocaml","ppx","ppx-extension"],"created_at":"2024-11-11T00:18:21.171Z","updated_at":"2025-04-26T07:31:15.666Z","avatar_url":"https://github.com/hammerlab.png","language":"OCaml","funding_links":[],"categories":[],"sub_categories":[],"readme":"# [@@deriving cmdliner]\n\n_deriving Cmdliner_ is the easiest way to get a command line interface.\n\nIt is also a [ppx_deriving](https://github.com/whitequark/ppx_deriving) plugin\nthat generates a [Cmdliner](https://github.com/dbuenzli/cmdliner) `Term` for a\ngiven type.\n\n![example workflow](https://github.com/hammerlab/ppx_deriving_cmdliner/actions/workflows/workflow.yml/badge.svg)\n\n## Example\n\n\n```ocaml\ntype params = {\n  username: string;\n  (** Your Github username *)\n\n  api_key: string;\n  (** Your Github API key *)\n\n  command: string; [@pos 0] [@docv \"CMD\"]\n  (** The Github API command to run *)\n\n  dry_run: bool;\n  (** Don't really run this command *)\n\n  time_to_wait: float; [@default 0.]\n  (** Just an example of another type *)\n} [@@deriving cmdliner, show]\n\nlet main () =\n  let f p = show_params p |\u003e print_endline in\n  let info = Cmdliner.Cmd.info Sys.argv.(0) in\n  let term = Cmdliner.Term.(const f $ params_cmdliner_term ()) in\n  let cmd = Cmdliner.Cmd.v info term in\n  exit (Cmdliner.Cmd.eval cmd)\n\nlet () = main ()\n```\n\nWhich gives you a CLI like the following:\n\n```\nNAME\n       awesome-cli\n\nSYNOPSIS\n       awesome-cli [OPTION]... CMD\n\nARGUMENTS\n       CMD (required)\n            The Github API command to run\n\nOPTIONS\n       --api-key=STRING (required)\n            Your Github API key\n\n       --dry-run\n            Don't really run this command\n\n       --help[=FMT] (default=auto)\n           Show this help in format FMT. The value FMT must be one of `auto',\n           `pager', `groff' or `plain'. With `auto', the format is `pager` or\n           `plain' whenever the TERM env var is `dumb' or undefined.\n\n       --time-to-wait=FLOAT (absent=0.)\n            Just an example of another type\n\n       --username=STRING (required)\n            Your Github username\n```\n\n## Features\n\n### Custom type support\n\nPpx_deriving_cmdliner supports arbitrary types via a `cmdliner_converter`\ninterface. For example, the below two methods work for supporting `M.t` (from\n`test/tests.ml`)\n\n```ocaml\nmodule M = struct\n  type t = int * int\n  let fst (f,_) = f\n  let snd (_,s) = s\n  let of_string s =\n    try\n      let sepi = String.index s '|' in\n      let fst = String.sub s 0 sepi in\n      let snd = String.sub s (sepi+1) ((String.length s)-sepi-1) in\n      Result.Ok (int_of_string fst, int_of_string snd)\n    with _ -\u003e Result.Error (`Msg (Printf.sprintf \"Couldn't parse `%s`\" s))\n  let to_string t =\n    Printf.sprintf \"%d|%d\" (fst t) (snd t)\n  let cmdliner_converter =\n    of_string,\n    (fun fmt t -\u003e Format.fprintf fmt \"%s\" (to_string t))\nend\ntype custom_types = {\n  foo: M.t; [@conv M.cmdliner_converter]\n  bar: M.t;\n} [@@deriving cmdliner]\n```\n\nIn short, a value of type ``string -\u003e ('a, [ `Msg of string ]) Result.result) *\n'a printer`` must be provided (or will be looked for under the name\n`cmdliner_converter` if the type is `t`, else `type_name_cmdliner_converter`)\nfor the given type.\n\n## Attributes supported\n\n1. Docs: `[@doc \"Overwrites the docstring\"]`, `[@docs \"SECTION TWO\"]`, `[@docv \"VAL\"]`\n2. Environment variables: `[@env \"ENVNAME\"]`, `[@env.doc \"Docs for the variable\"]`, `[@env.docs \"SECTION ENVS\"]`\n3. Other: `[@list_sep '@']`, `[@default 123]`, `[@enum [(\"a\", Foo); (\"b\", Bar)]]`, `[@aka [\"b\";\"another-flag-name\"]]`, `[@conv cmdliner_converter]` (cf. [required argument to `conv`](http://erratique.ch/software/cmdliner/doc/Cmdliner.Arg.html#VALconv) in Cmdliner), `[@opt_all]` only on `a' list` fields, `[@term cmdliner_term]` for assiging an arbitrary `Cmdliner.Term.t` to a field.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhammerlab%2Fppx_deriving_cmdliner","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhammerlab%2Fppx_deriving_cmdliner","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhammerlab%2Fppx_deriving_cmdliner/lists"}