medusa 0.1.0

General template for building command line interface (CLI) using (and written in) Rust
Documentation

medusa

General template for building command line interface (CLI) using (and written in) Rust

How to use

  • Add crates dependencies in your Cargo.toml
...

[dependencies]
medusa = "0.1.0"
...
  • Import the library
...
use medusa::{CommandLine, HandlerVariant};
...
  • Create example function as your CLI option handler
...
fn hello() {
  println!("Hello, world!");
}

fn echo(payload: String) {
  println!("payload : {}", payload);
}
...
  • Create your handler using HashMap
...
use std::collections::HashMap;

let mut handlers: HashMap<String, HandlerVariant> = HashMap::new();
handlers.insert(String::from("--hello"), HandlerVariant::Plain(hello));
handlers.insert(String::from("--echo"), HandlerVariant::WithArg(echo));
...
  • Register your handler into CLI command
...
use std::env;

let mut command: CommandLine = CommandLine::new();
command.set_handler(handlers);
command.run(env::args());
...
  • Test your Rust code if it's really works
cargo run -- --hello
cargo run -- --echo something
  • Compile your code
cargo build