argsys 0.0.21

Simple argument-handler library
Documentation
argsys-0.0.21 has been yanked.

ArgSys 0.0.2

At first, you need to create templates:

let mut templates: Vec<Arg> = Vec::new();

templates.push( build_arg("--help", Some("-h"), "Displays help") ); // example
// Trigger will be on --help or on -h

templates.push( build_arg("--list", None, "Displays configurations") ); // example
// Trigger will be on --list only

Next, you can get template index in array:


let arg_index: usize = 
    get_arg_index( templates.clone(), "--help".to_string() );

or:


use std::env;

let args: Vec<String> = env::args().collect();

for i in 1..args.len() { // Skip first argument
    let current: String = args[i].clone();

match get_arg_index( templates.clone(), current.clone() ) {

        Some(0) => {} // --help
        Some(1) => {} // --list

        None => {}
        _ => {}
    }
}

Support for 'description' field is coming soon.

And full example:


use argsys::*;
use std::env;

fn main() 
{
    // Create an array of templates
    let mut templates: Vec<Arg> = Vec::new();
    
    // Create templates
    templates.push( build_arg( "--help", Some("-h"), "Displays help" ) );
    templates.push( build_arg( "--list", None, "Displays configurations") );

    // Push args in array
    let args: Vec<String> = env::args().collect();

    for i in 1..args.len() {
        let current: String = args[i],clone();

        // Returns index of current in array or 'None' if not found
        match get_arg_index( templates.clone(), current.clone() ) {
            Some(0) => { println!("ArgSys help\n..."); }

            None => { println!("Not found: {}", current.clone()); }
            _ => {} 
        }
    }
}

ArgSys help - v0.0.1-0.0.2