Expand description
§clish
The most elegant CLI framework for Rust.
Inspired by Typer. Define commands as plain functions. The argument types determine how each parameter is parsed from the command line. Validation, help generation, and error reporting are automatic.
ⓘ
use clish::prelude::*;
#[command]
/// Deploy the application
fn deploy(target: Pos<String>, env: Named<String>, force: bool) {
println!("Deploying {} to {}", target, env);
}
fn main() {
app!().run();
}§Argument types
| Type | Behavior | Example |
|---|---|---|
Pos<T> | Positional, required | myapp cmd foo |
Pos<Option<T>> | Positional, optional | myapp cmd or myapp cmd foo |
Pos<Vec<T>> | Positional, variadic | myapp cmd a b c |
Named<T> | --name val, required | myapp cmd --env prod |
Named<Option<T>> | --name val, optional | |
Named<Vec<T>> | --name val, repeatable | myapp cmd --tag a --tag b |
bool | --flag presence | myapp cmd --force |
T must implement FromStr. Type mismatches produce colored errors
at runtime. Invalid type combinations (Option<Vec<T>>, Option<bool>)
are rejected at compile time.
§Parsing features
--name=valueand--name valueforms for named options-n valueand-nvalueforms with short aliases- Bundled short flags:
-abcis equivalent to-a -b -c --separator: everything after is treated as positional- Environment variable fallback via
param(x, env = "VAR") - Default values via
param(x, default = "val") - Value constraints via
param(x, choices = ["a", "b"]) - Mutual exclusion via
param(x, conflicts_with = ["y"]) - Prerequisites via
param(x, requires = ["y"])
§Re-exports
This crate re-exports everything you need from clish-core and clish-macros.
See prelude for a single-use convenience import.
Modules§
Macros§
Structs§
Enums§
- Error
Kind - Errors produced during argument parsing and validation.
Type Aliases§
- Flag
- A boolean CLI flag. Use
booldirectly in function signatures.
Attribute Macros§
- command
- Annotate a function as a CLI command.