type CliHit = { field: String, value: String }
One option seen in argv: the field it fills, and the text it carried ("" for a flag).
Type to search, or try , or .
4 exports, from std/cli.vyrn.
The command line is a record type, and cli writes its parser and help.
import { cli } from "std/cli" import { parseServe, helpServe } from cli("./serve")
cli is a gen fn that reflects a module of type declarations and returns a module exporting, for every exported record type, parse<Name>(argv) -> Validation<Name> and help<Name>() -> String. The compiler knows nothing about command lines. The mapping is a rule over the declaration, never an attribute:
| field type | surface | missing | |---|---|---| | Bool | --verbose | false | | Option<T> | --host <value> | None | | bare T | --port <value> | an Issue at path port | | Array<String> | the positionals, at most one field | empty |
dryRun is --dry-run.-h is reserved for --help.Issue: unlike std/args, a spec exists.--port 99999 reaches Port?(99999), and its None becomes an Issue worded from that type's Schema, so the parser and the program run one check./// above its named type (TypeInfo.schema.doc), so a documented option needs a named type.--help is a question about argv, not a value in the record: ask it with wantsHelp(argv) before parsing.A field is Bool, Int64, String, a validated type over Int64 or String, an Option of those, or one Array<String> for the positionals. Anything else fails the generation with a sentence naming the field.
Inspect the synthesized module with: vyrn emit-gen <file>
The import graph shows the whole library.
type CliHit = { field: String, value: String }
One option seen in argv: the field it fills, and the text it carried ("" for a flag).
type CliRead = { hits: Array<CliHit>, free: Array<String>, issues: Array<Issue>, }
What one walk of argv found: the options, the free arguments, and the problems with the argv itself (unknown option, missing value). The generated parser raises the problems with a value.
fn wantsHelp(argv: Array<String>) -> Bool
Whether --help or -h appears before a -- terminator. Ask it before parsing: a program asked for help has not given the required options.
gen fn cli(module: String) -> String
Emits a module exporting parse<Name> and help<Name> for every exported record type module declares.
9 test blocks in std/cli.vyrn. CI runs all of them.
2 programs in examples/ import this module. Each runs as WebAssembly and as a native binary.