Derive Macro cling::Run

source ·
#[derive(Run)]
{
    // Attributes available to this derive:
    #[cling]
    #[command]
    #[clap]
}
Expand description

Mark clap structs as cling runnable command.

This trait needs to be derived for clap structs or enums that will run a function handler or a if has subcommands. Note that cling requires that all clap structs/enums implement Clone.

Usually, this will be derived like the following example:

use cling::prelude::*;

#[derive(Run, Parser, Debug, Clone)]
#[cling(run = "do_nothing")]
pub struct App {
    /// Turn debugging information on
    #[arg(short, long, action = ArgAction::Count)]
    pub debug: u8,
}

fn do_nothing() {}

[Run] types will execute the handler specified in #[cling(run = "...")] The string value must be a valid path to a function.

Handler functions can be async or sync, cling will handle this transparently. However, Cling only supports async on the top level, you’ll need to pick an async runtime to execute the application.