1 unstable release
0.1.0 | Nov 18, 2022 |
---|
#1467 in Database interfaces
11KB
186 lines
pino_argparse is a bite-sized argparsing library that can handle short and long flags with or without values, subcommands and basic validation.
USING IN YOUR PROJECT
add the follow to your Cargo.toml
:
pino_argparse = { git = "https://github.com/MrPicklePinosaur/pino_argparse" }
TODO
- auto doc/help message generation?
- iterator to give flags in order
lib.rs
:
A simple arg parsing library with no dependencies.
Provide a schema for your cli application and attach handlers to each command. Query for flags values with support for short and long flag names, as well as optional parameters.
use pino_argparse::{Cli, Flag, FlagParse, Command};
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();
}