Expand description
A crate for parsing commands and arguemnts passed to the console.
This can parse commands with various arguments. It currently only supports option arguments (or args beginning with a “-”), but an update for regular params and argument rules (like ordering) will be coming soon.
§Getting Started
To start, create a new Parser
struct and add a couple of Arg
s to it using the
Parser::add_arg()
or Parser::add_args()
methods.
Then, call the Parser::parse()
method with std::env::Args
passed in.
use cli_parser::{ Parser, Arg };
use std::env;
fn main() {
let parser = Parser::new();
let my_arg = Arg::new().flag("help").short('h');
parser.add_arg(my_arg);
let mut args = env::args();
// Don't include the first argument
args.next();
let hashmap = parser.parse(&mut args).unwrap();
if hashmap.contains_key("help") {
println!("Help argument called!");
}
}