badargs 0.2.0

Type safe zero-dependency argument parser
Documentation
  • Coverage
  • 70%
    14 out of 20 items documented5 out of 14 items with examples
  • Size
  • Source code size: 28.05 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 667.98 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 12s Average build duration of successful builds.
  • all releases: 12s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • Noratrieb/badargs
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • Noratrieb

Node: badargs is not 1.0 yet, so it may change at any time. Use it with caution.

badargs

A zero-dependency full type-safe argument parser.

It's correct enough for what it does.

badargs handles non Utf8 input by just printing an error and exiting the program gracefully.

How to use

use badargs::arg;

arg!(OutFile: "output", 'o' -> String);
arg!(Force: "force", 'f' -> bool);
arg!(OLevel: "optimize" -> usize);

fn main() {
    let args = badargs::badargs!(OutFile, Force, OLevel);

    let outfile = args.get::<OutFile>();
    let force = args.get::<Force>();
    let o_level = args.get::<OLevel>();

    println!("output:     {:?}", outfile);
    println!("force:      {:?}", force);
    println!("o-level:    {:?}", o_level);
    println!("other args: {:?}", args.unnamed())
    
}

Use the badargs::arg! macro to declare arguments like this:
arg!(Binding, long_name, optional_short_name -> return_type)

The following return types are currently available:

  • String
  • bool
  • isize
  • usize
  • f64

Boolean values can only be None or Some(true).
The other values can be None or Some(_)

Todo

Being able to add more metadata for better --help or --version

Why doesn't badargs have x?

If you want a fully featured, even more type safe argument parser, use Clap, or structopt.

These do have a lot of dependencies and/or proc macros, so they are a lot more heavy compilation wise. Badargs is perfect for you if you don't want or need that.