medusa 0.2.1

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

Running the example

  • Run the example without arguments
cargo run --example simple
  • Run the example with arguments
cargo run --example simple -- --echo "hello universe"

How to use

  • Add crates dependencies in your Cargo.toml
...
[dependencies]
medusa = "0.2.1"
...
  • Import the library
...
use medusa::{CommandLine, Handler, Variant};
...
  • Create example function as your CLI option handler
...
fn hello() {
  println!("Hello, world!");
}

fn echo(payload: String) {
  println!("payload : {}", payload);
}
...
  • Create your handler and add some actions
...
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.")
);
...
  • Register your handler into CLI command
...
use std::env;

let mut command: CommandLine = CommandLine::new();
command.set_handler(handler);
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