A minimal CLI framework written in Rust
toml
[dependencies]
seahorse = "0.4.4"
bash
$ git clone https://github.com/ksk001100/seahorse
$ cd seahorse
$ cargo run --example single_app
$ cargo run --example multiple_app
```rust use std::env; use seahorse::{App, Command, color, Flag, FlagType, Context};
fn main() {
let args: Vec
app.run(args);
}
fn helloaction(c: &Context) { let name = &c.args[2]; if c.boolflag("bye") { println!("Bye, {}", name); } else { println!("Hello, {}", name); }
match c.int_flag("age") {
Some(age) => println!("{} is {} years old", name, age),
None => println!("I don't know {}'s age", name)
}
}
fn hellocommand() -> Command { Command::new() .name("hello") .usage("multipleapp hello [name]") .action(helloaction) .flags(vec![ Flag::new("bye", "multipleapp hello [name] --bye", FlagType::Bool), Flag::new("age", "multiple_app hello [name] --age [age]", FlagType::Int) ]) } ```
bash
$ cargo run
$ cargo run John --bye
$ cargo run John --age 30
```rust use std::env; use seahorse::{SingleApp, color, Context, Flag, FlagType};
fn main() {
let args: Vec
app.run(args);
}
fn action(c: &Context) { let name = &c.args[0]; if c.bool_flag("bye") { println!("Bye, {:?}", name); } else { println!("Hello, {:?}", name); } } ```
bash
$ cargo run
$ cargo run Bob
$ cargo run Bob --bye