pub fn parse(args: &Vec<String>) -> Result<Vec<Arguments>, Box<dyn Error>> {
        let mut arguments = Vec::new();
        let mut arg_options = ValidArguments::options();
        for arg in args {
            let (key, value) = Self::split_argument(arg)?;
            if arg_options.contains_key(&key) {
                let func = arg_options.remove(&key).unwrap().argument_function;
                arguments.push(func(&value)?);
            }
        }
        if arguments.is_empty() {
            Err("No Arguments found")?
        } else if !(arg_options.is_empty()) {
            let unused_keys = Self::get_unset_arguments(&arg_options);
            Err(format!("{}is missing", unused_keys))?
        } else {
            Ok(arguments)
        }
    }
/// Parse arguments with predfind options and return,
/// a vector with parsed data wrapped in Arguments Enum
/// # Examples
///
/// ```
/// let args: Vec<String> = env::args().skip(1).collect();
/// let arg = match Arguments::parse(&args) {
///         Ok(arguments) => arguments,
///         Err(error) => {
///             println!("\nError while parsing arguments: {}", error);
///             Arguments::help();
///             process::exit(1);
///         }
///     };
/// ```
Parse arguments with predfind options and return,
a vector with parsed data wrapped in Arguments Enum
Parse arguments with predfind options and return a vector with parsed data wrapped in Arguments Enum
pub fn parse(args: &Vec<String>) -> Result<Vec<Arguments>, Box<dyn Error>> {
        let mut arguments = Vec::new();
        let mut arg_options = ValidArguments::options();
        for arg in args {
            let (key, value) = Self::split_argument(arg)?;
            if arg_options.contains_key(&key) {
                let func = arg_options.remove(&key).unwrap().argument_function;
                arguments.push(func(&value)?);
            }
        }
        if arguments.is_empty() {
            Err("No Arguments found")?
        } else if !(arg_options.is_empty()) {
            let unused_keys = Self::get_unset_arguments(&arg_options);
            Err(format!("{}is missing", unused_keys))?
        } else {
            Ok(arguments)
        }
    }
pub fn parse ( args : & Vec < String > ) -> Result < Vec < Arguments > , Box < dyn Error > > { let mut arguments = Vec :: new ( ) ; let mut arg_options = ValidArguments :: options ( ) ; for arg in args { let ( key , value ) = Self :: split_argument ( arg ) ? ; if arg_options . contains_key ( & key ) { let func = arg_options . remove ( & key ) . unwrap ( ) . argument_function ; arguments . push ( func ( & value ) ? ) ; } } if arguments . is_empty ( ) { Err ( " " ) ? } else if ! ( arg_options . is_empty ( ) ) { let unused_keys = Self :: get_unset_arguments ( & arg_options ) ; Err ( format ! ( " " unused_keys ) ) ? } else { Ok ( arguments ) } }
Parse arguments with predfind options and return,
a vector with parsed data wrapped in Arguments Enum
Parse arguments with predfind options and return a vector with parsed data wrapped in Arguments Enum
args
&Vec<String>
args
&Vec<String>
examples
```
let args: Vec = env::args().skip(1).collect();
let arg = match Arguments::parse(&args) {
Ok(arguments) => arguments,
Err(error) => {
println!("\nError while parsing arguments: {}", error);
Arguments::help();
process::exit(1);
}
};
```
` ` ` let args : Vec = env :: args () . skip ( 1 ) . collect () ; let arg = match Arguments :: parse ( &args ) { Ok ( arguments ) = > arguments Err ( error ) = > { println! ( " \ nError while parsing arguments : {} " error ) ; Arguments :: help () ; process :: exit ( 1 ) ; } } ; ` ` `