Arguments & Flags¶
Arguments and flags let your commands accept user input. lets validates inputs, generates help text, and interpolates values into your shell commands automatically.
Positional arguments¶
Define with the arg node:
Default values¶
Make an argument optional with default:
Choices¶
Restrict values to a set of allowed options:
Help text¶
Multiple arguments¶
Commands can have multiple positional arguments:
Flags¶
Flags come in two types: boolean (on/off) and valued (takes a value).
Boolean flags¶
$ lets build # cargo build
$ lets build --release # cargo build --release
$ lets build -r # cargo build --release
The {?release:--release} syntax means: "if the release flag is set, emit --release; otherwise emit nothing."
Valued flags¶
Flags that take a value use the type property:
$ lets deploy # deploy --replicas 3
$ lets deploy --replicas 5 # deploy --replicas 5
$ lets deploy -r 5 # deploy --replicas 5
Supported types:
| Type | Example | Validation |
|---|---|---|
"string" |
--name taylor |
Any string |
"int" |
--count 5 |
Must be an integer |
"float" |
--factor 1.5 |
Must be a number |
If no type is specified, the flag is boolean.
Interpolation syntax¶
Placeholders in run, before, after, and confirm strings are replaced with values at execution time:
| Syntax | Description | Example |
|---|---|---|
{name} |
Positional arg, valued flag, or interactive variable | echo {name} |
{?flag:text} |
Emit text if boolean flag is set, empty otherwise |
{?verbose:--verbose} |
{--} |
All arguments after --, space-separated |
cargo test {--} |
{$VAR} |
Environment variable (node env first, then process env) | echo {$HOME} |
Passthrough arguments¶
The {--} placeholder passes through everything after --:
Conditional text¶
The {?flag:text} syntax emits text only when a boolean flag is set:
build {
flag verbose "-v"
flag release "-r"
run "cargo build {?verbose:--verbose} {?release:--release}"
}
Environment variable interpolation¶
Reference environment variables with {$VAR}:
The node's env values are checked first, then the process environment.
Combining args and flags¶
A command can have both arguments and flags: