pino_argparse is a bite-sized argparsing library that can handle short and long flags with or without values, subcommands and basic validation.
Add the following to your Cargo.toml
:
pino_argparse = { version = "0.1.0" }
A simple cli would look something like:
fn main() {
// Get arguments
let args = std::env::args().collect();
// Initialize the CLI
let cli = Cli {
program_name: "myprogram",
synopsis: "a simple program to show of the argparse library",
root_command: Command {
flags: vec![
Flag::new("help").short('h'),
Flag::new("verbose").short('v'),
],
handler: |flagparse: FlagParse| -> Result<(), Box<dyn std::error::Error>> {
if flagparse.get_flag("help") {
println!("We called the help flag!");
}
Ok(())
},
..Default::default()
},
..Default::default()
};
// Run the CLI
let flagparse = cli.run(&args).unwrap();
}
- auto doc/help message generation?
- iterator to give flags in order