Cli

The Cli module provides values-first command-line parsing helpers. It parses an explicit argument list with explicit specs and returns Result values. It does not read environment variables, inspect files, print help, or exit the process.

Pure Parser

Use Cli when application code should own argument sources, output, and error handling instead of delegating those effects to a parser.

Types

CliValueKind
CliStringKind | CliIntKind | CliBoolKind
Describes how a flag, option, or positional value should be parsed.
CliValue
CliString String | CliInt Int | CliBool Bool
The parsed value representation stored in ParsedOptions.values.
CliError
CliUnknownOption | CliMissingOptionValue | CliMissingRequired | CliInvalidValue | CliUnknownCommand | CliMissingCommand
Structured errors returned by parsing functions.

Spec Builders

Cli.flag
String -> String -> CliSpec
Declare a boolean flag parsed from --name.
Cli.option
String -> CliValueKind -> Option CliValue -> String -> CliSpec
Declare a named option parsed from --name value or --name=value.
Cli.arg
NonNegativeInt -> String -> CliValueKind -> Bool -> Option CliValue -> String -> CliSpec
Declare a positional argument by zero-based index.
Cli.command
String -> String -> List CliSpec -> CliCommandSpec
Declare a top-level subcommand and its option specs.

Parsing

Cli.parse
List String -> List CliSpec -> Result ParsedOptions CliError
Parse flags, options, and positional arguments from an argument list.
specs = [
  Cli.flag "verbose" "Enable verbose output",
  Cli.option "limit" CliIntKind (Some (CliInt 10)) "Maximum rows",
  Cli.arg 0 "input" CliStringKind true None "Input file"
]

parsed = Cli.parse ["--verbose", "--limit=25", "data.csv"] specs
Cli.parse-command
List String -> List CliCommandSpec -> Result ParsedCommand CliError
Parse a top-level subcommand and then parse that command's options.

Usage Text

Cli.usage
String -> List CliSpec -> String
Generate usage text from option declarations in declaration order.
Cli.command-usage
String -> List CliCommandSpec -> String
Generate command usage text from command declarations in declaration order.