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();
                Value::String(val)
            } else {
                Value::Bool(true)
            };

            argument.user_value = Some(arg_val);
        }

        // Check the constraints for the `required` and `requires` 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();
                Value::String(val)
            } else {
                Value::Bool(true)
            };
            argument.user_value = Some(arg_val);
        }
        // Check the constraints for the `required` and `requires` 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 ( ) ; Value :: String ( val ) } else { Value :: Bool ( true ) } ; argument . user_value = Some ( arg_val ) ; } // Check the constraints for the `required` and `requires` 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]