Skip to main content

cli

Attribute Macro cli 

Source
#[cli]
Expand description

Generate a CLI application from an impl block.

§Basic Usage

use server_less::cli;

#[cli]
impl MyApp {
    fn create_user(&self, name: String) { /* ... */ }
}

§With All Options

#[cli(
    name = "myapp",
    version = "1.0.0",
    description = "My awesome application"
)]
impl MyApp {
    /// Create a new user (becomes: myapp create-user <NAME>)
    fn create_user(&self, name: String) { /* ... */ }

    /// Optional flags use Option<T>
    fn list_users(&self, limit: Option<usize>) { /* ... */ }
}

§Generated Methods

  • cli_command() -> clap::Command - Complete CLI application
  • cli_run(&self) -> Result<(), ...> - Execute CLI and handle result (sync entry point with tokio)
  • cli_run_with(&self, matches: &ArgMatches) -> Result<(), ...> - Execute a pre-parsed command
  • cli_run_async(&self) -> impl Future<...> - Runtime-agnostic async entry point
  • cli_run_with_async(&self, matches: &ArgMatches) -> impl Future<...> - Async with pre-parsed matches