ezcli

Crates.ioezcli
lib.rsezcli
version0.4.0
sourcesrc
created_at2020-03-15 03:49:58.093825
updated_at2022-10-03 08:48:31.588124
descriptionEasy CLI crate for Rust
homepage
repositoryhttps://github.com/Aliics/ezcli
max_upload_size
id218751
size15,134
Alexander Johnston (Aliics)

documentation

README

ezcli

Small and lightweight enough to be put into any CLI application quickly with no fuss. Just call a macro or two and it's up and running!

If you do want a more fleshed out CLI crate, you should check out clap.

how to use

ezcli is pretty easy to use and nothing too crazy is happening. Using flag! or option! will allow for them to be passed as CLI args and it even creates a nifty little variable for you to use once the macro has been called. Note that the macros will replace underscores (_) with hyphens (-) in the arguments name.

flag

Command line argument for a boolean state. The flag! macro only requires a variable name. Once invoked, it will check the command line arguments for a matching flag. Optionally, passing the keyword let will create a variable with the same name as the flag.

use ezcli::flag;

if flag!(--my_boolean) { // "--my-boolean" exists in arguments
    // do stuff because flag is given
}

// OR

flag!(let --my_boolean);

if my_boolean { // "--my-boolean" exists in arguments
    // do stuff because flag is given
}

option

Command line argument for an optional parameter. The option! macro requires a variable name, like flag!, and will create a variable if let is included. The value will be the next argument wrapped in a Some, unless it is not provided then it'll be None.

use ezcli::option;

match option!(--my_arg) {
    Some(x) => {}, // use x
    None => {}, // handle no value
}

// OR 

option!(let --my_arg);

match my_arg {
    Some(x) => {}, // use x
    None => {}, // handle no value
}

short- and long-name arguments

A command line argument can be in short-name (indicated by 1 hyphen: -a) or long-name (indicated by 2 hyphens: --arg). This applies to both flag! and option!.

use ezcli::{flag, option};

if flag!(-f, --flag) { 
    // "-f" or "--flag" exists in arguments
}

// "-a" or "--arg" exists in arguments
match option!(-a, --arg) {
    Some(x) => {},
    None => {},
}

// OR

let my_flag = flag!(-f, --flag);
...

See flag and option tests for more detailed examples.

Commit count: 49

cargo fmt