#argument #argv #cli #command


An argument parsing and validation library designed to take some of tediousness out of the general 'getopts' crate

9 stable releases

Uses old Rust 2015

2.2.0 Feb 27, 2018
2.1.0 Apr 16, 2017
2.0.4 Jul 13, 2016
2.0.2 Apr 6, 2016
0.1.1 Mar 13, 2016

#184 in Command-line interface

Download history 123/week @ 2023-11-04 104/week @ 2023-11-11 153/week @ 2023-11-18 191/week @ 2023-11-25 104/week @ 2023-12-02 112/week @ 2023-12-09 143/week @ 2023-12-16 168/week @ 2023-12-23 63/week @ 2023-12-30 323/week @ 2024-01-06 135/week @ 2024-01-13 112/week @ 2024-01-20 155/week @ 2024-01-27 133/week @ 2024-02-03 283/week @ 2024-02-10 387/week @ 2024-02-17

973 downloads per month
Used in 6 crates (5 directly)

MIT license



A dead simple implementation of command line argument parsing and validation built on top of the getopts crate.

In order to use the args crate simply create an Args object and begin registering possible command line options via the flag(...) and option(...) methods. Once all options have been registered, parse arguments directly from the command line, or provide a vector of your own arguments.

Any errors encountered during parsing will be returned wrapped in an ArgsError. If there are no errors during parsing values may be retrieved from the args object by simply calling value_of(...) and validated_value_of(...).

That's it!


This crate is on crates.io and can be used by adding args to the dependencies in your project's Cargo.toml.

args = "2.0"

and this to your crate root:

extern crate args;


The following example shows simple command line parsing for an application that requires a number of iterations between zero (0) and ten (10) to be specified, accepts an optional log file name and responds to the help flag.

extern crate args;
extern crate getopts;

use getopts::Occur;
use std::process::exit;

use args::{Args,ArgsError};
use args::validations::{Order,OrderValidation};

const PROGRAM_DESC: &'static str = "Run this program";
const PROGRAM_NAME: &'static str = "program";

fn main() {
    match parse(&vec!("-i", "5")) {
        Ok(_) => println!("Successfully parsed args"),
        Err(error) => {
            println!("{}", error);

fn parse(input: &Vec<&str>) -> Result<(), ArgsError> {
    let mut args = Args::new(PROGRAM_NAME, PROGRAM_DESC);
    args.flag("h", "help", "Print the usage menu");
        "The number of times to run this program",
        "The name of the log file",


    let help = try!(args.value_of("help"));
    if help {
        return Ok(());

    let gt_0 = Box::new(OrderValidation::new(Order::GreaterThan, 0u32));
    let lt_10 = Box::new(OrderValidation::new(Order::LessThanOrEqual, 10u32));

    let iters = try!(args.validated_value_of("iter", &[gt_0, lt_10]));
    for iter in 0..iters {
        println!("Working on iteration {}", iter);

    let optional_val = try!(Self::optional_value_of::<String>(&args, SERVICE));
    if let Some(val) = optional_val {
        // val is `Some`
    } else {
        // val is `None`

    println!("All done.");