You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
bubbyroosh da5e854eb3 Allow just '-' to be returned instead of removed 3 months ago
src Allow just '-' to be returned instead of removed 3 months ago
.gitignore Initial Commit 3 months ago
Cargo.toml Allow just '-' to be returned instead of removed 3 months ago
LICENSE Initial Commit 3 months ago
README.md add method to get unused arguments; unsafe 😭 3 months ago

README.md

arg_dot_h

Argument parser somewhat following the style seen in many C applications:

Example:

use std::process;

use arg_dot_h::*;

fn help(argv0: &str) {
    println!("{} [-b] [-s string]", argv0);
    process::exit(1);
}

fn main() {
    let mut argv0 = String::new();
    let mut testbool = false;
    let mut teststring = String::new();

    // Parses std::env::args(). If an argument starts with '-', it will remove the '-' and iterate
    // over the chars. After everything is parsed, anything that didn't start with '-' or wasn't taken with eargf is returned in a Vec<String>
    let args = argbegin! {
        // First argument is the variable the name of the program will be set to (since it can be renamed)
        &mut argv0,
        // All other arguments are like a match statement for each char in a valid argument.
        // Run when the char is 'b'
        'b' => testbool = true,
        // eargf! returns the next argument. If a function (help(&argv0)) is passed, it will run
        // that if there isn't a next argument. Otherwise it will return an empty string.
        's' => teststring = eargf!(help(&argv0)),
        // If the char doesn't match anything else, run the help function.
        _ => help(&argv0)
    };

    /* If "-bs mystring more args" was passed, it would output:
    true mystring
    more
    args
    */
    println!("{} {}", testbool, teststring);
    args.iter().for_each(|arg| println!("{}", arg));
}