Coder Social home page Coder Social logo

rgparse's Introduction

RgParse - A Rust Command-line Argument Parser

A very simple command line argument parser.

A Simple Example

// The argument to `new` is the description for the application.
let mut parser = Parser::new("An example argument parsing application");
// Adds some `param` parameters, which take a single value.
// There is no special requirement for parameter prefixes. `-/--` are used here by convention.
// Aliases and default values can be specified using the builder pattern.
parser.add_parameter(Parameter::param("--arg0", "Argument 0, type: u32.").alias("-a").default(&5));
// Adds a flag parameter, which takes no value - it is `true` if present, `false` otherwise
parser.add_parameter(Parameter::flag("--arg1", "Argument 1, flag").alias("-a1"));

// Parsing arguments returns an `Args` struct which has 3 major features.
let args = parser.parse_args();

// 1. You can access positional arguments directly.
for positional in &args.positional {
    println!("Found positional argument: {}", positional);
}

// 2. The `get` function allows you to access parameters.
let arg0 = args.get::<u32>("--arg0");
println!("Arg 0 was {}", arg0);

// 3. The `flag` function allows you to check the value of flags.
if args.flag("--arg2") {
    println!("Found Arg 2 flag!");
}

rgparse's People

Contributors

pmarathe25 avatar

Watchers

James Cloos 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.