seahorse

crates.io releases count issues count forks count lisence travis build

Logo

A minimal CLI framework written in Rust

Using

toml [dependencies] seahorse = "0.4.4"

Example

bash $ git clone https://github.com/ksk001100/seahorse $ cd seahorse $ cargo run --example single_app $ cargo run --example multiple_app

Multiple action application

```rust use std::env; use seahorse::{App, Command, color, Flag, FlagType, Context};

fn main() { let args: Vec = env::args().collect(); let app = App::new() .name("multipleapp") .author(env!("CARGOPKGAUTHORS")) .description(env!("CARGOPKGDESCRIPTION")) .usage("multipleapp [command] [arg]") .version(env!("CARGOPKGVERSION")) .commands(vec![hello_command()]);

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

Single action application

```rust use std::env; use seahorse::{SingleApp, color, Context, Flag, FlagType};

fn main() { let args: Vec = env::args().collect(); let app = SingleApp::new() .name("singleapp") .author(env!("CARGOPKGAUTHORS")) .description(env!("CARGOPKGDESCRIPTION")) .usage("singleapp [args]") .version(env!("CARGOPKGVERSION")) .action(action) .flags(vec![ Flag::new("bye", "single_app args --bye", FlagType::Bool), ]);

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