General template for building command line interface (CLI) using (and written in) Rust
bash
cargo run --example simple
bash
cargo run --example simple -- --echo "hello universe"
Cargo.toml
toml
...
[dependencies]
medusa = "0.2.0"
...
rust
...
use medusa::{CommandLine, Handler, Variant};
...
```rust ... fn hello() { println!("Hello, world!"); }
fn echo(payload: String) { println!("payload : {}", payload); } ... ```
rust
...
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.")
);
...
```rust ... use std::env;
let mut command: CommandLine = CommandLine::new(); command.set_handler(handler); command.run(env::args()); ... ```
bash
cargo run -- --hello
cargo run -- --echo something
bash
cargo build