package cmdlang

  1. Overview
  2. Docs

Declarative Command-line Parsing for OCaml.

Cmdlang is a library for creating command-line parsers in OCaml. Implemented as an OCaml EDSL, its declarative specification language lives at the intersection of other well-established similar libraries.

Cmdlang exposes a single module named Command, which contains the entire API to declare command line parsers.

Assuming Cmdlang.Command to be available in your scope as Command, the following is a minimalist command that does nothing:

let cmd : unit Command.t =
  Command.make
    ~summary:"A command that does nothing"
    (let open Command.Std in
     let+ () = Arg.return () in
     ())
;;

To get started with this API refers to this tutorial from cmdlang's documentation.

Utils

module Nonempty_list : sig ... end

A type to represent lists that are statically known to be non-empty.

Interfaces

These interfaces are convenient to use with the Param module, so you can apply its helpers to custom modules. For example, if your module My_enum implements the Enumerated_stringable interface, then you can build a parser for it with:

Param.enumerated (module My_enum)
module type Enumerated_stringable = sig ... end

An interface for types that have a finite number of inhabitants that all have a canonical string representation.

module type Stringable = sig ... end

An interface for types that can be parsed from strings, when parsing never results in failures.

module type Validated_string = sig ... end

An interface for types that can be parsed from strings, with the possibility of parsing failures.

Parameters

module Param : sig ... end

Arguments

module Arg : sig ... end

Commands

type 'a t
val make : ?readme:(unit -> string) -> 'a Arg.t -> summary:string -> 'a t
val group : ?default:'a Arg.t -> ?readme:(unit -> string) -> summary:string -> (string * 'a t) list -> 'a t
module type Applicative_infix = sig ... end

For use with the ( let+ ) style.

module type Applicative_syntax = sig ... end

Let operators

For use with the ( let+ ) style:

let cmd : unit Command.t =
  Command.make
    ~summary:"A command that does nothing"
    (let open Command.Std in
     let+ () = Arg.return () in
     ())
;;
module Std : sig ... end

Ppx_let

For use with the ( let%map_open.Command ) style:

let cmd : unit Command.t =
  Command.make
    ~summary:"A command that does nothing"
    (let%map_open.Command () = Arg.return () in
     ())
;;
module Let_syntax : sig ... end

Private

This module is exported to be used by libraries with strong ties to cmdlang. Its signature may change in breaking ways at any time without prior notice, and outside of the guidelines set by semver.

module Private : sig ... end
OCaml

Innovation. Community. Security.