Giter Site home page Giter Site logo

badargs's Introduction

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.

badargs's People

Contributors

noratrieb avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.