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",
    about = "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_app() -> clap::Command - Complete CLI application
  • cli_run(&self, matches: &ArgMatches) - Execute matched command