23 releases (6 stable)

2.2.0 Mar 7, 2022
2.0.1 Apr 2, 2021
2.0.0 Dec 3, 2020
2.0.0-alpha.3 Nov 30, 2020
0.8.0 Jul 17, 2020

#494 in Command-line interface

Download history 12/week @ 2024-07-20 16/week @ 2024-07-27 29/week @ 2024-08-03 14/week @ 2024-08-10 9/week @ 2024-08-17 1/week @ 2024-08-24 14/week @ 2024-08-31 20/week @ 2024-09-07 13/week @ 2024-09-14 48/week @ 2024-09-21 16/week @ 2024-09-28 16/week @ 2024-10-05 27/week @ 2024-10-12 13/week @ 2024-10-19 10/week @ 2024-10-26 33/week @ 2024-11-02

86 downloads per month
Used in 3 crates

0BSD license

19KB
310 lines

Arguably

A ridiculously simple Rust library for parsing command line arguments.


lib.rs:

A minimalist library for parsing command line arguments.

Features

  • Long-form boolean flags with single-character shortcuts: --flag, -f.
  • Long-form string-valued options with single-character shortcuts: --option <arg>, -o <arg>.
  • Condensed short-form options: -abc <arg> <arg>.
  • Automatic --help and --version flags.
  • Support for multivalued options.
  • Support for git-style command interfaces with arbitrarily-nested commands.

Example

let mut parser = ArgParser::new()
    .helptext("Usage: foobar...")
    .version("1.0")
    .option("bar b", "default")
    .flag("foo f");

if let Err(err) = parser.parse() {
    err.exit();
}

if parser.found("foo") {
    println!("Flag --foo/-f found.");
}

println!("Option --bar/-b has value: {}", parser.value("bar"));

for arg in parser.args {
    println!("Arg: {}", arg);
}

No runtime deps