pieces

Crates.iopieces
lib.rspieces
version0.2.0
sourcesrc
created_at2021-09-13 00:18:46.134536
updated_at2021-09-28 00:29:30.831515
descriptionA argument parser. Built with
homepagehttps://github.com/ibx34/pieces
repositoryhttps://github.com/ibx34/pieces
max_upload_size
id450246
size42,968
Shadow Wizurd Money Gang Leader (ibx34)

documentation

https://docs.rs/pieces/0.1.1/pieces/

README

Pieces

An argument parser built with control in mind.

Parsing

The results you get are dependent on what order you parse in. If you want to say only parse positional arguemnts then only call .parse_args(). If you want to parse flag arguments before posistional (for some odd reason) then call .parse_flags() before calling .parse_args(). The example belows parsing of positional arguments before flag arguments.

Example

use piecesv2;

let parser = &mut piecesv2::parser::Parser::build2(
    std::env::args(),
    vec![], // Commands, not currently implemented...
    vec![
        piecesv2::args::Arg::new("name"), // First positional argument
        piecesv2::args::Arg::new("age"), // Second positional argument

        piecesv2::args::Arg::new("email") // First flag argument
            .short("e")
            .long("email")
            .set(piecesv2::args::ArgSettings::HAS_VALUE), // Takes value

        piecesv2::args::Arg::new("phone-number") // Second flag argument
            .short("p")
            .long("phone-number")
            .set(piecesv2::args::ArgSettings::HAS_VALUE)   
            .set(piecesv2::args::ArgSettings::MULTIPLE), // Allows multiple of this flag
    ] // Args and Flags.
);

// Parses only positional arguments:
let results = parser.parse_args();

if !results.contains_key(&String::from("age")) {
    panic!("Age is a required argument that wasn't provided.");
}

// Parsers only flags:
let flags = parser.parse_flags();

if !flags.contains_key(&String::from("email")) {
    panic!("Email is a required flag that wasn't provided.");
}
Commit count: 12

cargo fmt