# medusa
General template for building command line interface (CLI) using (and written in) Rust
## Running the example
- Run the example without arguments
```bash
cargo run --example simple
```
- Run the example with arguments
```bash
cargo run --example simple -- --echo "hello universe"
```
## How to use
- Add crates dependencies in your `Cargo.toml`
```toml
...
[dependencies]
medusa = "0.2.0"
...
```
- Import the library
```rust
...
use medusa::{CommandLine, Handler, Variant};
...
```
- Create example function as your CLI option handler
```rust
...
fn hello() {
println!("Hello, world!");
}
fn echo(payload: String) {
println!("payload : {}", payload);
}
...
```
- Create your handler and add some actions
```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.")
);
...
```
- Register your handler into CLI command
```rust
...
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
```bash
cargo run -- --hello
cargo run -- --echo something
```
- Compile your code
```bash
cargo build
```