1 unstable release

Uses old Rust 2015

0.1.0 Oct 6, 2016

#46 in #thin

Download history 12/week @ 2023-11-21 9/week @ 2023-11-28 2/week @ 2023-12-05 10/week @ 2023-12-12 12/week @ 2023-12-19 2/week @ 2023-12-26 2/week @ 2024-01-02 11/week @ 2024-01-09 6/week @ 2024-01-16 2/week @ 2024-02-06 12/week @ 2024-02-13 38/week @ 2024-02-20 27/week @ 2024-02-27 19/week @ 2024-03-05

98 downloads per month
Used in exercism_prep_tests

MIT license

4KB

clioptions

💲 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);
    }
}

No runtime deps