cli_args

Macro cli_args 

Source
macro_rules! cli_args {
    ( $( $name:ident : $ty:ty = $default:expr ),* $(,)? ) => { ... };
}
Expand description

Argument extraction macro

This macro provides a convenient way to extract command-line arguments with default values in a single expression. It automatically parses the command line, so you don’t need to call parse_command_line() yourself.

§Syntax

use cli_command::cli_args;
 
fn main() -> Result<(), Box<dyn std::error::Error>> {
    let (port, host, verbose) = cli_args!(
        port: u16 = 8080,
        host: String = "localhost".to_string(),
        verbose: bool = false
    );
    Ok(())
}

§Examples

use cli_command::cli_args;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let (port, host, workers, verbose) = cli_args!(
        port: u16 = 8080,
        host: String = "localhost".to_string(),
        workers: usize = 4,
        verbose: bool = false
    );
     
    println!("Server: {}:{} (workers: {}, verbose: {})", host, port, workers, verbose);
    Ok(())
}