yafp 0.2.0

yafp is a non-POSIX cli flag parser with imperative style flag declaration instead of the usual declarative style.
Documentation
  • Coverage
  • 100%
    18 out of 18 items documented3 out of 12 items with examples
  • Size
  • Source code size: 23.51 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.87 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 10s Average build duration of successful builds.
  • all releases: 10s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • joaonsantos/yafp
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • joaonsantos

yafp

Build Status Crates.io Documentation Rust 2021

yafp is a non-POSIX cli flag parser with imperative style flag declaration instead of the usual declarative style.

Features:

  • Help generation.
  • Imperative flag declaration with usage text.
  • Supports boolean flags, false by default and true if set.
  • Supports required and optional value flags.
  • Values parsed to assigned variable type.

Limitations:

  • Only supports short flag style.
  • Does not support flag combination, for example, -fd is not -f and -d and is instead a single flag.
  • Non-UTF8 arguments are not supported.

Usage

use yafp::Parser;

fn main() {
    let mut parser = Parser::from_env();
    
    // Declare flags.
    parser.bool_flag("verbose", "this is used to get verbose output");
    parser.required_flag("url", "this is a required flag");
    parser.required_flag("workers", "this is an optional flag");

    // finalize() must be called before accessing arguments.
    // Unbound args are returned if any.
    //
    // An error is returned if there is a parsing error.
    let result = parser.finalize();
    let remaining = match result {
        Ok(remaining) => remaining,
        Err(e) => {
            println!("{}: {}", parser.command, e);
            exit(1);
        }
    };
    
    // yafp parses values to the correct type.
    let verbose: bool = parser.get_value("verbose").unwrap();
    
    //...
}

License

MIT