clioptions

Crates.ioclioptions
lib.rsclioptions
version0.1.0
sourcesrc
created_at2016-10-06 17:31:16.26456
updated_at2016-10-06 17:31:16.26456
descriptionA very thin wrapper for command line arguments in Rust.
homepagehttps://github.com/stpettersens/clioptions
repositoryhttps://github.com/stpettersens/clioptions
max_upload_size
id6741
size4,203
Sam Saint-Pettersen (stpettersens)

documentation

https://stpettersens.github.io/clioptions/doc/clioptions

README

clioptions

:heavy_dollar_sign: A very thin wrapper for command line arguments in Rust.

Build Status Build status

Usage:
  • Add this to your Cargo.toml file.
[dependencies]
clioptions = { git = "https://github.com/stpettersens/clioptions.git" }
  • Implement your command line arguments.
extern crate clioptions;
use clioptions::CliOptions;

fn main() {
    let cli = CliOptions::new("program_name"); // "program_name" is the fallback for argv[0].
    let program = cli.get_program();
    let mut filename = String::new();
    if cli.get_num() > 1 {
        for (i, a) in cli.get_args().iter().enumerate() {
            match a.trim() {
                "-h" | "--help" => display_usage(&program, 0),
                "-v" | "--version" => display_version(),
                "-f" | "--file" => filename = cli.next_argument(i), 
                // next_argument(i) gets the argument after i.
                _ => continue,
            }
        }
    }
    if(!filename.is_empty()) {
        do_something_with_filename(&filename);
    }
}
Commit count: 25

cargo fmt