fn populate_args(&mut self, args: &[String]) -> Result<()> {
        let mut iter = args.iter();

        while let Some(arg) = iter.next() {
            self.validate_arg(arg)?;

            // If the `arg` argument is indeed an expected one, set the value provided by user
            // if it's a valid one.
            let argument = self
                .args
                .get_mut(&arg[ARG_PREFIX.len()..])
                .ok_or_else(|| Error::UnexpectedArgument(arg[ARG_PREFIX.len()..].to_string()))?;

            let arg_val = if argument.takes_value {
                let val = iter
                    .next()
                    .filter(|v| !v.starts_with(ARG_PREFIX))
                    .ok_or_else(|| Error::MissingValue(argument.name.to_string()))?
                    .clone();

                if argument.allow_multiple {
                    match argument.user_value.take() {
                        Some(Value::Multiple(mut v)) => {
                            v.push(val);
                            Value::Multiple(v)
                        }
                        None => Value::Multiple(vec![val]),
                        _ => return Err(Error::UnexpectedArgument(argument.name.to_string())),
                    }
                } else {
                    Value::Single(val)
                }
            } else {
                Value::Flag
            };

            argument.user_value = Some(arg_val);
        }

        // Check the constraints for the `required`, `requires` and `forbids` fields of all arguments.
        self.validate_requirements(&args)?;

        Ok(())
    }
/// Validate the arguments provided by user and their values. Insert those
/// values in the `Argument` instances of the corresponding arguments.
Validate the arguments provided by user and their values. Insert those
values in the `Argument` instances of the corresponding arguments.
Validate the arguments provided by user and their values . Insert those values in the ` Argument ` instances of the corresponding arguments .
fn populate_args(&mut self, args: &[String]) -> Result<()> {
        let mut iter = args.iter();
        while let Some(arg) = iter.next() {
            self.validate_arg(arg)?;
            // If the `arg` argument is indeed an expected one, set the value provided by user
            // if it's a valid one.
            let argument = self
                .args
                .get_mut(&arg[ARG_PREFIX.len()..])
                .ok_or_else(|| Error::UnexpectedArgument(arg[ARG_PREFIX.len()..].to_string()))?;
            let arg_val = if argument.takes_value {
                let val = iter
                    .next()
                    .filter(|v| !v.starts_with(ARG_PREFIX))
                    .ok_or_else(|| Error::MissingValue(argument.name.to_string()))?
                    .clone();
                if argument.allow_multiple {
                    match argument.user_value.take() {
                        Some(Value::Multiple(mut v)) => {
                            v.push(val);
                            Value::Multiple(v)
                        }
                        None => Value::Multiple(vec![val]),
                        _ => return Err(Error::UnexpectedArgument(argument.name.to_string())),
                    }
                } else {
                    Value::Single(val)
                }
            } else {
                Value::Flag
            };
            argument.user_value = Some(arg_val);
        }
        // Check the constraints for the `required`, `requires` and `forbids` fields of all arguments.
        self.validate_requirements(&args)?;
        Ok(())
    }
fn populate_args ( & mut self , args : & [ String ] ) -> Result < ( ) > { let mut iter = args . iter ( ) ; while let Some ( arg ) = iter . next ( ) { self . validate_arg ( arg ) ? ; // If the `arg` argument is indeed an expected one, set the value provided by user // if it's a valid one. let argument = self . args . get_mut ( & arg [ ARG_PREFIX . len ( ) .. ] ) . ok_or_else ( | | Error :: UnexpectedArgument ( arg [ ARG_PREFIX . len ( ) .. ] . to_string ( ) ) ) ? ; let arg_val = if argument . takes_value { let val = iter . next ( ) . filter ( | v | ! v . starts_with ( ARG_PREFIX ) ) . ok_or_else ( | | Error :: MissingValue ( argument . name . to_string ( ) ) ) ? . clone ( ) ; if argument . allow_multiple { match argument . user_value . take ( ) { Some ( Value :: Multiple ( mut v ) ) => { v . push ( val ) ; Value :: Multiple ( v ) } None => Value :: Multiple ( vec ! [ val ] ) , _ => return Err ( Error :: UnexpectedArgument ( argument . name . to_string ( ) ) ) , } } else { Value :: Single ( val ) } } else { Value :: Flag } ; argument . user_value = Some ( arg_val ) ; } // Check the constraints for the `required`, `requires` and `forbids` fields of all arguments. self . validate_requirements ( & args ) ? ; Ok ( ( ) ) }
Validate the arguments provided by user and their values.
Validate the arguments provided by user and their values .
&mut self
args
&[String]
&mut self
args
&[String]