rawcmd

Crates.iorawcmd
lib.rsrawcmd
version0.6.3
sourcesrc
created_at2020-04-13 21:27:27.507775
updated_at2020-07-01 19:15:05.148514
descriptionCommand-line application framework.
homepagehttps://github.com/xpepermint/rawcmd
repositoryhttps://github.com/xpepermint/rawcmd
max_upload_size
id229820
size45,646
Kristijan Sedlak (xpepermint)

documentation

https://github.com/xpepermint/rawcmd

README

Command-line application framework.

Usage

The command line parser will search for the following pattern:

$ myapp <COMMAND> <FLAGS> <PARAMS> -- <TAIL>

A simple command-line application could look something like this:

use rawcmd::{Context, Command, Flag, Intent};

fn main() {
    match Command::with_name("foo")
        .with_description("Command 1")
        .with_flag(
            Flag::with_name("flag1")
                .with_alias("f1")
                .with_description("Flag 1")
        )
        .with_param(
            Param::with_name("param1")
                .with_description("Param 1")
        )
        .with_subcommand(
            Command::with_name("bar")
                .with_description("Command 1:1")
                .with_flag(
                    Flag::with_name("flag2")
                        .with_alias("f2")
                        .with_description("Flag 2")
                )
                .with_resolver(|_intent, &mut _context| Ok(2))
        )
        .with_resolver(|_intent, &mut _context| Ok(3))
        .with_handler(|_error, _intent, &mut _context| Ok(4))
        .run(
            &mut Context::default(),
        )
    {
        Ok(code) => {
            println!("Success: {:?}", code);
            std::process::exit(0);
        },
        Err(error) => {
            println!("Error: {:?}", error);
            std::process::exit(1);
        },
    }
}

You can use your own custom context object as well:

...
.run<MyContext>(
    MyContext::default()
)
Commit count: 49

cargo fmt