package ppx_deriving_cmdliner

  1. Overview
  2. Docs
Cmdliner.Term.t generator

Install

Dune Dependency

Authors

Maintainers

Sources

v0.0.0.tar.gz
md5=976fd6fac87489ad76f81f10329fe1b8

Description

ppx_deriving_cmdliner is a ppx_deriving plugin that generates Cmdliner Terms for types.

Tags

syntax cli

Published: 10 Mar 2017

README

[@@deriving cmdliner]

deriving Cmdliner is the easiest way to get a command line interface.

It is also a ppx_deriving plugin that generates a Cmdliner Term for a given type.

Example

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]

let _ =
  let term = Cmdliner.Term.(const show_params $ params_cmdliner_term ()) in
  tlet info = Cmdliner.Term.info Sys.argv.(0) in
  Cmdliner.Term.eval (term, info)

Which gives you a CLI like the following:

NAME
       awesome-cli

SYNOPSIS
       awesome-cli [OPTION]... CMD

ARGUMENTS
       CMD (required)
            The Github API command to run

OPTIONS
       --api-key=STRING (required)
            Your Github API key

       --dry-run
            Don't really run this command

       --help[=FMT] (default=auto)
           Show this help in format FMT. The value FMT must be one of `auto',
           `pager', `groff' or `plain'. With `auto', the format is `pager` or
           `plain' whenever the TERM env var is `dumb' or undefined.

       --time-to-wait=FLOAT (absent=0.)
            Just an example of another type

       --username=STRING (required)
            Your Github username

Attributes supported

  1. Docs: [@doc "Overwrites the docstring", [@docs "SECTION TWO"], [@docv "VAL"]

  2. Environment variables: [@env "ENVNAME"], [@env.doc "Docs for the variable"], [@env.docs "SECTION ENVS"]

  3. Other: [@list_sep '@'], [@default 123], [@enum [("a", Foo); ("b", Bar)]], [@aka ["b";"another-flag-name"]]

Dependencies (7)

  1. cppo_ocamlbuild build
  2. cppo build
  3. ocamlfind build
  4. ppx_deriving >= "4.0" & < "4.3"
  5. result
  6. cmdliner
  7. ocaml < "4.10"

Dev Dependencies (2)

  1. ppx_import with-test & >= "1.1" & < "2.0"
  2. alcotest with-test

Used by (1)

  1. ppx_subliner

Conflicts

None