All Projects β†’ hammerlab β†’ Ppx_deriving_cmdliner

hammerlab / Ppx_deriving_cmdliner

Licence: apache-2.0
Ppx_deriving plugin for generating command line interfaces from types (Cmdliner.Term.t)

Programming Languages

ocaml
1615 projects

Projects that are alternatives of or similar to Ppx deriving cmdliner

Commander
πŸš€The framework to write type-safe and structured command line program easily in Swift.
Stars: ✭ 170 (+117.95%)
Mutual labels:  cli, command-line-parser
Typin
Declarative framework for interactive CLI applications
Stars: ✭ 126 (+61.54%)
Mutual labels:  cli, command-line-parser
Clikt
Multiplatform command line interface parsing for Kotlin
Stars: ✭ 1,658 (+2025.64%)
Mutual labels:  cli, command-line-parser
Libcmdf
Single-header library for writing CLI applications in C/C++
Stars: ✭ 30 (-61.54%)
Mutual labels:  cli, command-line-parser
Caporal.js
A full-featured framework for building command line applications (cli) with node.js
Stars: ✭ 3,279 (+4103.85%)
Mutual labels:  cli, command-line-parser
Picocli
Picocli is a modern framework for building powerful, user-friendly, GraalVM-enabled command line apps with ease. It supports colors, autocompletion, subcommands, and more. In 1 source file so apps can include as source & avoid adding a dependency. Written in Java, usable from Groovy, Kotlin, Scala, etc.
Stars: ✭ 3,286 (+4112.82%)
Mutual labels:  cli, command-line-parser
Spectre.cli
An extremely opinionated command-line parser.
Stars: ✭ 121 (+55.13%)
Mutual labels:  cli, command-line-parser
Argparse
Argparse for golang. Just because `flag` sucks
Stars: ✭ 294 (+276.92%)
Mutual labels:  cli, command-line-parser
Argh
Argh! A minimalist argument handler.
Stars: ✭ 752 (+864.1%)
Mutual labels:  cli, command-line-parser
Clii
Python 3.7+ function annotations -> CLI
Stars: ✭ 41 (-47.44%)
Mutual labels:  cli, command-line-parser
Instascrape
πŸš€ A fast and lightweight utility and Python library for downloading posts, stories, and highlights from Instagram.
Stars: ✭ 76 (-2.56%)
Mutual labels:  cli
Cognitocurl
πŸ¦‰πŸ€–Easily sign curl calls to API Gateway with Cognito authorization token.
Stars: ✭ 76 (-2.56%)
Mutual labels:  cli
Batchit
simple jobs submission via command-line for AWS batch
Stars: ✭ 77 (-1.28%)
Mutual labels:  cli
Pilgo
Configuration-based dotfiles manager
Stars: ✭ 78 (+0%)
Mutual labels:  cli
Nostromo
CLI for building powerful aliases
Stars: ✭ 76 (-2.56%)
Mutual labels:  cli
Tools
Game development tools for the Amethyst engine
Stars: ✭ 76 (-2.56%)
Mutual labels:  cli
Click
The "Command Line Interactive Controller for Kubernetes"
Stars: ✭ 1,198 (+1435.9%)
Mutual labels:  cli
Hr
A horizontal πŸ“ for your terminal
Stars: ✭ 1,195 (+1432.05%)
Mutual labels:  cli
Vcli
Vertica CLI with auto-completion and syntax highlighting
Stars: ✭ 75 (-3.85%)
Mutual labels:  cli
Tty Prompt
A beautiful and powerful interactive command line prompt
Stars: ✭ 1,210 (+1451.28%)
Mutual labels:  cli

[@@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
  let 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

Features

Custom type support

Ppx_deriving_cmdliner supports arbitrary types via a cmdliner_converter interface. For example, the below two methods work for supporting M.t (from test/tests.ml)

module M = struct
  type t = int * int
  let fst (f,_) = f
  let snd (_,s) = s
  let of_string s =
    try
      let sepi = String.index s '|' in
      let fst = String.sub s 0 sepi in
      let snd = String.sub s (sepi+1) ((String.length s)-sepi-1) in
      Result.Ok (int_of_string fst, int_of_string snd)
    with _ -> Result.Error (`Msg (Printf.sprintf "Couldn't parse `%s`" s))
  let to_string t =
    Printf.sprintf "%d|%d" (fst t) (snd t)
  let cmdliner_converter =
    of_string,
    (fun fmt t -> Format.fprintf fmt "%s" (to_string t))
end
type custom_types = {
  foo: M.t; [@conv M.cmdliner_converter]
  bar: M.t;
} [@@deriving cmdliner]

In short, a value of type string -> ('a, [ `Msg of string ]) Result.result) * 'a printer must be provided (or will be looked for under the name cmdliner_converter if the type is t, else type_name_cmdliner_converter) for the given type.

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"]], [@conv cmdliner_converter] (cf. required argument to conv in Cmdliner), [@opt_all] only on a' list fields, [@term cmdliner_term] for assiging an arbitrary Cmdliner.Term.t to a field.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].