Crate subcmd [−] [src]
Cargo style subcommand
This library help to build an app that use a similar command line interface as Cargo or Git.
Example
The following example show a simple program with two subcommand:
cargo build
cargo clean
extern crate subcmd; use subcmd::CmdHandler; use subcmd::Command; struct CmdBuild; impl Command for CmdBuild { fn name<'a>(&self) -> &'a str {"build"} fn help<'a>(&self) -> &'a str {"Usage: cargo build [options]"} fn description<'a>(&self) -> &'a str { "Compile the current project" } fn run(&self, argv: &Vec<String>) { println!("I'm building your files"); } } struct CmdClean; impl Command for CmdClean { fn name<'a>(&self) -> &'a str {"clean"} fn help<'a>(&self) -> &'a str {"Usage: cargo clean [options]"} fn description<'a>(&self) -> &'a str { "Remove the target directory" } fn run(&self, argv: &Vec<String>) { println!("I'm cleaning your files"); } } fn main() { let mut handler = CmdHandler::new(); handler.add(Box::new(CmdBuild)); handler.add(Box::new(CmdClean)); handler.run(); }
Structs
CmdHandler |
Command line parser and subcommand runner |
CmdWrapper |
This wrapper hold a command object and a arguments vectors. |
Message |
A Message to be printed |
Enums
CmdResult |
Result of a CmdHandler::run |
Traits
Command |
This trait must be implemented for each subcommand |