Crate pino_argparse

source ·
Expand description

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

Structs

Base struct to define the schema for your cli application.
Struct describing a command
Information on a flag
Parsed flag information

Type Definitions