Crates.io | medusa |
lib.rs | medusa |
version | 0.3.0 |
source | src |
created_at | 2020-02-26 17:05:19.713605 |
updated_at | 2020-03-21 14:02:30.954873 |
description | General template for building command line interface (CLI) using (and written in) Rust |
homepage | |
repository | https://gitlab.com/tardi/medusa |
max_upload_size | |
id | 212748 |
size | 33,958 |
General template for building command line interface (CLI) using (and written in) Rust
cargo run --example simple
cargo run --example simple -- --echo "hello universe"
cargo run --example stateful -- --echo "hello universe" --twice
Cargo.toml
...
[dependencies]
medusa = "0.3.0"
...
...
use medusa::{ArgType, CommandLine, Handler, Variant};
...
...
fn hello(handler: &Handler) {
println!("Hello, world!");
}
fn echo(handler: &Handler, payload: String) {
println!("payload : {}", payload);
}
fn print_twice(handler: &Handler) {
if let Some(argtype) = handler.get_arg("--echo") {
if let ArgType::Content(payload) = argtype {
println!("printed once more : {}", payload);
}
}
}
...
...
let mut handler: Handler = Handler::new();
handler.add(
String::from("--hello"),
Variant::Plain(hello),
String::from("Print hello world for testing purpose.")
);
handler.add(
String::from("--echo"),
Variant::WithArg(echo),
String::from("Print string passed to this parameter to output.")
);
handler.add(
String::from("--twice"),
Variant::Plain(print_twice),
String::from("Print again the payload \"--echo\" have."),
);
...
...
use std::env;
let mut command: CommandLine = CommandLine::new();
command.set_handler(handler);
command.set_name("mycli");
command.set_version("1.0.0");
command.run(env::args());
...
cargo run -- --hello
cargo run -- --echo something
cargo run -- --echo greatstring --twice
cargo build