jaarg 0.1.1

It can parse your arguments you should use it it's called jaarg
Documentation
  • Coverage
  • 51.79%
    29 out of 56 items documented0 out of 29 items with examples
  • Size
  • Source code size: 50.15 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 4.62 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 18s Average build duration of successful builds.
  • all releases: 17s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • ScrelliCopter

jaarg argument parser library

nostd & (mostly) const, some say it can parse your arguments.

Obligatory fancy banners

Example usage

// Variables for arguments to fill
let mut file = PathBuf::new();
let mut out: Option<PathBuf> = None;
let mut number = 0;

// Set up arguments table
enum Arg { Help, Number, File, Out }
const OPTIONS: Opts<Arg> = Opts::new(&[
  Opt::help_flag(Arg::Help, &["-h", "--help"]).help_text("Show this help and exit."),
  Opt::value(Arg::Number, &["-n", "--number"], "value")
    .help_text("Optionally specify a number (default: 0)"),
  Opt::positional(Arg::File, "file").required()
    .help_text("Input file."),
  Opt::positional(Arg::Out, "out")
    .help_text("Output destination (optional).")
]).with_description("My simple utility.");

// Parse command-line arguments from `std::env::args()`
match OPTIONS.parse_easy(|program_name, id, _opt, _name, arg| {
  match id {
    Arg::Help => {
      OPTIONS.print_full_help(program_name);
      return Ok(ParseControl::Quit);
    }
    Arg::Number => { number = str::parse(arg)?; }
    Arg::File   => { file = arg.into(); }
    Arg::Out    => { out = Some(arg.into()); }
  }
  Ok(ParseControl::Continue)
}) {
  ParseResult::ContinueSuccess => (),
  ParseResult::ExitSuccess     => std::process::exit(0),
  ParseResult::ExitError       => std::process::exit(1),
}

// Print the result variables
println!("{file:?} -> {out:?} (number: {number:?})",
  out = out.unwrap_or(file.with_extension("out")));

Changelog

v0.1.1:

  • Fixed incorrect error message format for coerced parsing errors.
  • Cleaned up docstring formatting.
  • Added basic example.

v0.1.0:

  • Initial release.

Projects using jaarg (very cool)