Clap: Command-Line Argument Parsing

Clap is a library for command-line argument parsing. Clap works by directly consuming arguments in an imperative way. Traditionally, argument parsing in OCaml is done by first defining a specification (an OCaml value defining the types of arguments), and then parsing from this specification. The "impure" approach of Clap skips the need to define a specification and results in code which is quite simple in practice, with limited boilerplate.

Clap does construct a specification internally as arguments are parsed. It uses it to generate the --help, following usual man page conventions.

Installation

Clap is available as an opam package:

opam install clap

To use it, add clap as a dependency in your dune file.

API Documentation

See src/clap.mli.

Example

See demo/demo.ml.

The Two Rules

One limitation of Clap is that you have to follow two rules which are not enforced by typing:

There are exceptions to these rules.