ace

Crates.ioace
lib.rsace
version0.2.0
sourcesrc
created_at2019-07-24 08:29:09.696432
updated_at2020-01-17 04:53:48.505033
descriptionParsing command line arguments
homepage
repository
max_upload_size
id151313
size10,391
(wyhaya)

documentation

README

ace

GitHub Workflow Status Crates.io LICENSE

A simple command line parameter parsing library

Install

Add this in your Cargo.toml:

[dependencies]
ace = "0.2.0"

Example

use ace::App;

fn main() {
    let app = App::new()
        .config("app", env!("CARGO_PKG_VERSION"))
        .cmd("start", "Start now")
        .cmd("help", "Display help information")
        .cmd("version", "Display version information")
        .opt("--config", "Use configuration file")
        .opt("--duration", vec!["Set duration of test", "example (1ms, 1s, 1m, 1h, 1d)"])
        .opt("--timeout", "Set timeout");

    if let Some(cmd) = app.command() {
        match cmd.as_str() {
            "start" => {
                dbg!(app.value("--config"));
            }
            "help" => {
                app.print_help();
            }
            "version" => {
                app.print_version();
            }
            _ => {
                app.print_error_try("help");
            }
        }
    } else {
        dbg!(app.args());
    }
}

Output:

app version 0.2.0

Usage:
    app [COMMAND] [OPTION]
            
Command:
    start      Start now
    help       Display help information
    version    Display version information

Option:
    --config      Use configuration file
    --duration    Set duration of test
                  example (1ms, 1s, 1m, 1h, 1d)
    --timeout     Set timeout
Commit count: 0

cargo fmt