28 releases (12 stable)

Uses old Rust 2015

1.1.7 Jun 23, 2024
1.1.6 Mar 30, 2024
1.1.4 Jan 19, 2024
1.1.3 Jan 6, 2022
0.3.1 Nov 30, 2018

#567 in Command line utilities

Download history 64/week @ 2024-10-07 48/week @ 2024-10-14 43/week @ 2024-10-21 56/week @ 2024-10-28 45/week @ 2024-11-04 2/week @ 2024-11-11 27/week @ 2024-11-18 41/week @ 2024-11-25 53/week @ 2024-12-02 127/week @ 2024-12-09 84/week @ 2024-12-16 11/week @ 2024-12-23 10/week @ 2024-12-30 33/week @ 2025-01-06 66/week @ 2025-01-13 70/week @ 2025-01-20

180 downloads per month
Used in 12 crates (11 directly)

BSD-3-Clause-Clear

28KB
463 lines

getopt

A minimal, (essentially) POSIX-compliant option parser.

getopt::Parser iterates over the provided arguments, producing options one at a time in the order in which they are given on the command line, and stopping at the first non-option argument.

Example:

#![allow(unused_assignments, unused_variables)]

use getopt::Opt;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut args: Vec<String> = std::env::args().collect();
    let mut opts = getopt::Parser::new(&args, "ab:");

    let mut a_flag = false;
    let mut b_flag = String::new();
    loop {
        match opts.next().transpose()? {
            None => break,
            Some(opt) => match opt {
                Opt('a', None) => a_flag = true,
                Opt('b', Some(string)) => b_flag = string.clone(),
                _ => unreachable!(),
            }
        }
    }

    let args = args.split_off(opts.index());

    //

    Ok(())
}

No runtime deps

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy