Skip to content

MrPicklePinosaur/pino_argparse

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pino_argparse

a tiny zero-dependency argparsing library

crates.io docs.rs MIT/Apache 2.0

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 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();
}

TODO

  • auto doc/help message generation?
  • iterator to give flags in order

About

a tiny zero-dependency argparsing library

Topics

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Packages

No packages published