Skip to main content

Crate clish

Crate clish 

Source
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

TypeBehaviorExample
Pos<T>Positional, requiredmyapp cmd foo
Pos<Option<T>>Positional, optionalmyapp cmd or myapp cmd foo
Pos<Vec<T>>Positional, variadicmyapp cmd a b c
Named<T>--name val, requiredmyapp cmd --env prod
Named<Option<T>>--name val, optional
Named<Vec<T>>--name val, repeatablemyapp cmd --tag a --tag b
bool--flag presencemyapp 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=value and --name value forms for named options
  • -n value and -nvalue forms with short aliases
  • Bundled short flags: -abc is 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§

help
Help text rendering: styles and printers.
prelude
Convenience module for a single use import.

Macros§

app
Construct an App with metadata from Cargo.toml.

Structs§

App
The top-level CLI application.
Named
A named CLI option.
Pos
A positional CLI argument.

Enums§

ErrorKind
Errors produced during argument parsing and validation.

Type Aliases§

Flag
A boolean CLI flag. Use bool directly in function signatures.

Attribute Macros§

command
Annotate a function as a CLI command.