A minimal argument parser

Overview

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.");
}
You might also like...
☄🌌️  The minimal, blazing-fast, and infinitely customizable prompt for any shell
☄🌌️ The minimal, blazing-fast, and infinitely customizable prompt for any shell

☄🌌️ The minimal, blazing-fast, and infinitely customizable prompt for any shell

A minimal readline with multiline and async support
A minimal readline with multiline and async support

RustyLine Async A minimal readline with multiline and async support. Inspired by rustyline , async-readline & termion-async-input.

Minimal Pandoc compiler - HTML

Minimal Pandoc compiler - HTML

82 fun and easy to use, lightweight, spinners for Rust, with minimal overhead.
82 fun and easy to use, lightweight, spinners for Rust, with minimal overhead.

Spinners for Rust 82 fun and easy to use, lightweight, spinners for Rust, with minimal overhead, all the way from simple dots, to fun emoji based "spi

Fast, minimal, feature-rich, extended formatting syntax for Rust!

Formatting Tools Fast, minimal, feature-rich, extended formatting syntax for Rust! Features include: Arbitrary expressions inside the formatting brace

Minimal recursive "truncate file/directory names to meet requirements" tool

trunc_filenames ssokolow@monolith ~ % trunc_filenames --help trunc_filenames 0.1.0 Rename files and directories to fit length limits. WARNING: Will n

Minimal and blazing-fast file server. For real, this time.

Zy Minimal and blazing-fast file server. For real, this time. Features Single Page Application support Partial responses (Range support) Cross-Origin

Minimal server (with maximal security) for turning off an X10-controlled fan over HTTP

"Fan Remote" A self-contained Rust binary to expose a single X10 command (turn off that fan) as an HTML form button. In its current form, it's highly

MinMon - an opinionated minimal monitoring and alarming tool

MinMon - an opinionated minimal monitoring and alarming tool (for Linux) This tool is just a single binary and a config file. No database, no GUI, no

Docopt for Rust (command line argument parser).

THIS CRATE IS UNMAINTAINED This crate is unlikely to see significant future evolution. The primary reason to choose this crate for a new project is if

null 743 Jan 1, 2023
A full featured, fast Command Line Argument Parser for Rust

clap Command Line Argument Parser for Rust It is a simple-to-use, efficient, and full-featured library for parsing command line arguments and subcomma

Ed Page 0 Jun 16, 2022
A simple, lightweight and extensible command line argument parser for rust codebases

A simple, lightweight and extensible command line argument parser for rust codebases. This crate aims to provide you with an easy-to-use and extensibl

Victor Ndaba 20 Nov 12, 2022
Argument parsing for the future 🚀

argi Argument parsing for the future ?? Features Macro-based approach, providing an intuitive way to layout a cli Rich auto-help generation, styling b

Owez 132 Oct 23, 2022
argmax is a library that allows Rust applications to avoid Argument list too long errors (E2BIG) by providing a std::process::Command wrapper with a

argmax argmax is a library that allows Rust applications to avoid Argument list too long errors (E2BIG) by providing a std::process::Command wrapper w

David Peter 22 Nov 20, 2022
Rust derive-based argument parsing optimized for code size

Argh Argh is an opinionated Derive-based argument parser optimized for code size Derive-based argument parsing optimized for code size and conformance

Google 1.3k Dec 28, 2022
A language parser tool to build recursive descent top down parser.

lang-pt A language parser tool to generate recursive descent top down parser. Overview Parsers written for the languages like Javascript are often cus

Creative Forest 7 Jan 4, 2023
A minimal CLI framework written in Rust

seahorse A minimal CLI framework written in Rust Features Easy to use No dependencies Typed flags(Bool, String, Int, Float) Documentation Here Usage T

Keisuke Toyota 223 Dec 30, 2022
A hackable, minimal, fast TUI file explorer, stealing ideas from nnn and fzf.

xplr A hackable, minimal, fast TUI file explorer, stealing ideas from nnn and fzf. [Quickstart] [Features] [Plugins] [Documentation] [Upgrade Guide] [

Arijit Basu 2.6k Jan 1, 2023
⚡️ Lightning-fast and minimal calendar command line. Written in Rust 🦀

⚡️ Lightning-fast and minimal calendar command line. It's similar to cal. Written in Rust ??

Arthur Henrique 36 Jan 1, 2023