Argument Types Reference
This page lists every argument type clish supports, along with behavior details and compile-time restrictions.
Type table
| Type | Kind | Required? | Behavior | Example invocation |
|---|---|---|---|---|
Pos<T> |
Positional | Yes | Reads the next positional value | myapp cmd foo |
Pos<Option<T>> |
Positional | No | Reads the next positional value if available | myapp cmd or myapp cmd foo |
Pos<Vec<T>> |
Positional | No (zero or more) | Reads all remaining positional values | myapp cmd a b c |
Named<T> |
Named option | Yes | Reads the value after --name |
myapp cmd --env prod |
Named<Option<T>> |
Named option | No | Reads the value after --name if provided |
|
Named<Vec<T>> |
Named option | No (repeatable) | Collects all values for --name |
myapp cmd --tag a --tag b |
bool |
Flag | No | True if --name is present, false otherwise |
myapp cmd --force |
Type parameter constraints
The inner type T must implement FromStr. Built-in types that work include:
| Type | Description |
|---|---|
String |
Any text |
i8, i16, i32, i64, i128 |
Signed integers |
u8, u16, u32, u64, u128 |
Unsigned integers |
f32, f64 |
Floating point numbers |
bool |
Boolean (parsed from "true"/"false") |
PathBuf |
File system path |
| Custom types | Any type implementing FromStr |
Parse failures produce a runtime error:
error: invalid value 'abc': expected u16
|
1 | myapp serve --port abc
| ^^^
|
= hint: run 'myapp serve --help' for more information
Compile-time restrictions
The following type combinations are rejected at compile time:
| Rejected type | Reason | Fix |
|---|---|---|
Option<Vec<T>> |
Vec<T> already accepts zero or more values |
Use Vec<T> |
Option<bool> |
Flags are already optional by presence | Use bool |
Multiple Pos<Vec<T>> |
Only one variadic positional is allowed per command | Use a single Pos<Vec<T>> |
Pos<Vec<T>> not last |
Variadic must consume all remaining positionals | Move it to the last positional position |
Named option syntax
Named options support several input forms:
| Form | Example |
|---|---|
--name value |
--env production |
--name=value |
--env=production |
-n value (with short alias) |
-e production |
-nvalue (with short alias) |
-eproduction |
Flag syntax
Flags support these forms:
| Form | Example |
|---|---|
--flag |
--force |
-f (with short alias) |
-f |
| Bundled short flags | -vf (equivalent to -v -f) |
When bundling short flags, only flags (not options) can be combined. If a short option appears in a bundle, the parser stops and reports that the option is missing its value.
Positional argument separator
Use -- to signal that all following arguments are positional, even if they look like flags:
myapp process -- -file.txt --not-a-flag
Everything after -- is treated as a positional value.