Standard library
CLI flags
Parse flags and positionals from argv.
Introduction
Parse flags and positionals from argv. Import std/cli to bind the module as cli. Call free functions as cli.name(...). Struct methods use a receiver value.
/ std/cli
This page is the package reference for std/cli. Private helpers used only by co-located tests are not listed.
Functions
Free functions on cli. Each function has a short description, an example, then parameters and return shape.
parse
Parses an argv list into flags and positionals. Call form: cli.parse(argv).
/ std/cli
$ parsed = cli.parse(["--name", "ada", "file.echo"])
Parameters: argv: list of argument strings (often process.args()). Returns: Parsed product with flag and positional fields.
has
Reports whether a long flag is present on a parse result. Call form: cli.has(tokens, name).
/ std/cli
$ parsed = cli.parse(["--help"])
$ on = cli.has(parsed, "help")
Parameters: parsed: value from cli.parse. flag: flag name without leading dashes. Returns: Boolean true when the flag is set.
get
Reads the value of a long flag from a parse result. Call form: cli.get(tokens, name).
/ std/cli
$ parsed = cli.parse(["--name", "ada"])
| cli.get(parsed, "name") {
$ v { }
: { }
}Parameters: parsed: value from cli.parse. flag: flag name without leading dashes. Returns: Option. Some arm: flag value string. None arm: flag absent.
positionals
Returns positional arguments from a parse result. Call form: cli.positionals(tokens).
/ std/cli
$ parsed = cli.parse(["--x", "1", "a.echo"])
$ rest = cli.positionals(parsed)
Parameters: parsed: value from cli.parse. Returns: List of positional strings.