veko doc
Self-Contained API Reference • Gradual Types • Capabilities • Wasm Sandbox

cli

lib/cli.vk

lib/cli.vk Pure-Veko declarative CLI option parser, subcommand router, and --help formatter. Zero capabilities required.

FlagSpec struct
signature
FlagSpec = struct { name str, short str = ..., kind enum = ..., required bool = ..., default_val any = ..., help str = ... }

Describes a single CLI flag (--name, optional -s, and value kind .bool, .i64, .str, or .list).

CmdSpec struct
signature
CmdSpec = struct { name str, summary str = ..., flags block[FlagSpec] = ..., min_args i64 = ... }

Describes a CLI subcommand and its command-specific flags.

CliSpec struct
signature
CliSpec = struct { name str, version str = ..., summary str = ..., flags block[FlagSpec] = ..., commands block[CmdSpec] = ... }

Top-level specification for a command-line application.

CliResult struct
signature
CliResult = struct { command str = ..., flags map = ..., args block[str] = ..., help_requested bool = ..., version_requested bool = ... }

Parsed command-line invocation produced by cli/parse.

signature
parse = fn [spec CliSpec, argv block[str]] CliResult

Parses argv according to spec, validating flag types, short clusters (-abc), --key=value syntax, subcommands, required flags, and -- positional separation.

Executable Example
veko
use [cli]
spec = cli/CliSpec {
  name = 'demo'
  flags = [
    cli/FlagSpec { name = 'port', short = 'p', kind = .i64, default_val = 8080 }
    cli/FlagSpec { name = 'verbose', short = 'v', kind = .bool, default_val = false }
  ]
}
res = cli/parse spec ['-v' '--port=9090' 'input.vk']
if (cli/flag-i64 res 'port' 0) != 9090 or (not (cli/flag-bool res 'verbose')) [
  err 'cli/parse mismatch'
] else [ .ok ]
signature
flag-str = fn [res CliResult, name str, fallback str] str

Retrieves a string flag value from res, falling back to fallback.

signature
flag-i64 = fn [res CliResult, name str, fallback i64] i64

Retrieves an i64 flag value from res, falling back to fallback.

signature
flag-bool = fn [res CliResult, name str] bool

Retrieves a boolean flag value from res (defaults to false).

signature
flag-list = fn [res CliResult, name str] block

Retrieves a repeatable .list flag value from res (defaults to []).

signature
render-help = fn [spec CliSpec] str

Renders a clean --help usage guide for spec.

Executable Example
veko
use [cli]
spec = cli/CliSpec { name = 'mytool', version = '1.0.0', summary = 'Example tool' }
h = cli/render-help spec
if not (str/contains? h 'Usage: mytool') [ err 'render-help mismatch' ] else [ .ok ]