Declarative command-line argument parser with GNU-style options, positional arguments, subcommands, and auto-generated help.
Supports long (--opt v, --opt=v) and short (-o v, -o=v, -oVAL)
option forms, short boolean bundles (-rfv), bool negation aliases
(--no-<flag>), typed validation (string, number, boolean, file, dir),
repeatable options, choice constraints, and Levenshtein-based typo
suggestions. -- stops option parsing; remaining tokens are positional.
| Name | Signature |
|---|---|
| format_help | format_help(cmd) -> help |
| command | command(name, opts) -> cmd |
| format_error | format_error(err) -> message |
format_help(
cmd) ->help
Generate markdown-formatted help text for a command
Returns a markdown string with the following sections:
# <command> — name heading## Usage — generated usage line## Options — pipe table with name, default, forms, and note columns## Arguments — pipe table with name, arity, default, and note columns## Subcommands — pipe table (when present)Inline code spans carry semantic classes for themed rendering:
.bool, .num, .str, .file, .dir.opt, .arg, .flag, .meta.req, .def, .multi, .negcommand(
name,opts) ->cmd
Create a new command parser with options, arguments, and subcommands
Returns a command object with chainable builder methods:
cmd:summary(text) — set one-line summarycmd:description(text) — set longer descriptioncmd:option(name, spec) — add a named option (see option spec below)cmd:argument(name, spec) — add a positional argument (see argument spec below)cmd:command(name, spec) — add a subcommand (spec is a function or table with summary/description)cmd:build() — finalize configurationcmd:parse(argv) — parse an argument listThe opts table accepts default_subcommand (string) and
subcommand_required (boolean, defaults to true).
Fields for the spec table passed to cmd:option(name, spec):
short — one-char short alias (e.g. "v" for -v)long — explicit long name (default: name with _ → -)type or kind — "boolean", "string", "number", "file", "dir" (aliases: "bool", "str", "num")default — default valuerequired — require option presence (default: false)repeatable — collect repeated values into an array (default: false)negatable — allow/disallow auto --no-<long> for bools (default: true)choices — allowed values listmetavar — help placeholder for the valuenote or help — help textFields for the spec table passed to cmd:argument(name, spec):
type or kind — same type system as optionsnargs — one of "1", "?", "*", "+" (default: "1")default — default when omittedrequired — explicit requirement (inferred from nargs when not set)note or help — help textOn success, cmd:parse(argv) returns (parsed, nil) where parsed
is a table keyed by option/argument names. When subcommands are used,
parsed also contains subcommand (name) and args (sub-parsed table).
On failure or help, returns (nil, err) where err is a table:
kind — "help" or "parse_error"code — stable error code: help, unknown_option, missing_value,
invalid_value, invalid_negation, missing_option, missing_argument,
invalid_argument, unknown_subcommand, missing_subcommandmessage — human-readable messageusage — generated usage stringsuggestions — optional list of Levenshtein-based alternativesformat_error(
err) ->message
Format a parse error into a human-readable string
Formats the error table returned by cmd:parse() into a displayable
string. Combines usage line, error message, and suggestions (when
present). For err.kind == "help", returns the markdown help directly.