Validate the supplied arguments to the command.
Throws warnings or errors if arguments are missing
or invalid.

@param array $args
@param array $assoc_args
@param array $extra_args
@return array list of invalid $assoc_args keys to unset
332924
private function validate_args( $args, $assoc_args, $extra_args ) {
		$synopsis = $this->get_synopsis();
		if ( ! $synopsis ) {
			return array( array(), $args, $assoc_args, $extra_args );
		}

		$validator = new \WP_CLI\SynopsisValidator( $synopsis );

		$cmd_path = implode( ' ', get_path( $this ) );
		foreach ( $validator->get_unknown() as $token ) {
			\WP_CLI::warning(
				sprintf(
					'The `%s` command has an invalid synopsis part: %s',
					$cmd_path,
					$token
				)
			);
		}

		if ( ! $validator->enough_positionals( $args ) ) {
			$this->show_usage();
			exit( 1 );
		}

		$unknown_positionals = $validator->unknown_positionals( $args );
		if ( ! empty( $unknown_positionals ) ) {
			\WP_CLI::error(
				'Too many positional arguments: ' .
				implode( ' ', $unknown_positionals )
			);
		}

		$synopsis_spec = \WP_CLI\SynopsisParser::parse( $synopsis );
		$i             = 0;
		$errors        = array(
			'fatal'   => array(),
			'warning' => array(),
		);
		$mock_doc      = array( $this->get_shortdesc(), '' );
		$mock_doc      = array_merge( $mock_doc, explode( "\n", $this->get_longdesc() ) );
		$mock_doc      = '/**' . PHP_EOL . '* ' . implode( PHP_EOL . '* ', $mock_doc ) . PHP_EOL . '*/';
		$docparser     = new \WP_CLI\DocParser( $mock_doc );
		foreach ( $synopsis_spec as $spec ) {
			if ( 'positional' === $spec['type'] ) {
				$spec_args = $docparser->get_arg_args( $spec['name'] );
				if ( ! isset( $args[ $i ] ) ) {
					if ( isset( $spec_args['default'] ) ) {
						$args[ $i ] = $spec_args['default'];
					}
				}
				if ( isset( $spec_args['options'] ) ) {
					if ( ! empty( $spec['repeating'] ) ) {
						do {
							// phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict -- This is a loose comparison by design.
							if ( isset( $args[ $i ] ) && ! in_array( $args[ $i ], $spec_args['options'] ) ) {
								\WP_CLI::error( 'Invalid value specified for positional arg.' );
							}
							$i++;
						} while ( isset( $args[ $i ] ) );
					} else {
						// phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict -- This is a loose comparison by design.
						if ( isset( $args[ $i ] ) && ! in_array( $args[ $i ], $spec_args['options'] ) ) {
							\WP_CLI::error( 'Invalid value specified for positional arg.' );
						}
					}
				}
				$i++;
			} elseif ( 'assoc' === $spec['type'] ) {
				$spec_args = $docparser->get_param_args( $spec['name'] );
				if ( ! isset( $assoc_args[ $spec['name'] ] ) && ! isset( $extra_args[ $spec['name'] ] ) ) {
					if ( isset( $spec_args['default'] ) ) {
						$assoc_args[ $spec['name'] ] = $spec_args['default'];
					}
				}
				if ( isset( $assoc_args[ $spec['name'] ] ) && isset( $spec_args['options'] ) ) {
					// phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict -- This is a loose comparison by design.
					if ( ! in_array( $assoc_args[ $spec['name'] ], $spec_args['options'] ) ) {
						$errors['fatal'][ $spec['name'] ] = "Invalid value specified for '{$spec['name']}'";
					}
				}
			}
		}

		list( $returned_errors, $to_unset ) = $validator->validate_assoc(
			array_merge( \WP_CLI::get_config(), $extra_args, $assoc_args )
		);
		foreach ( array( 'fatal', 'warning' ) as $error_type ) {
			$errors[ $error_type ] = array_merge( $errors[ $error_type ], $returned_errors[ $error_type ] );
		}

		if ( 'help' !== $this->name ) {
			foreach ( $validator->unknown_assoc( $assoc_args ) as $key ) {
				$suggestion    = Utils\get_suggestion(
					$key,
					$this->get_parameters( $synopsis_spec ),
					$threshold = 2
				);

				$errors['fatal'][] = sprintf(
					'unknown --%s parameter%s',
					$key,
					! empty( $suggestion ) ? PHP_EOL . "Did you mean '--{$suggestion}'?" : ''
				);
			}
		}

		if ( ! empty( $errors['fatal'] ) ) {
			$out = 'Parameter errors:';
			foreach ( $errors['fatal'] as $key => $error ) {
				$out .= "\n {$error}";
				$desc = $docparser->get_param_desc( $key );
				if ( '' !== $desc ) {
					$out .= " ({$desc})";
				}
			}

			\WP_CLI::error( $out );
		}

		array_map( '\\WP_CLI::warning', $errors['warning'] );

		return array( $to_unset, $args, $assoc_args, $extra_args );
	}
993763
public function additionalArgs(array $args) : void
    {
        foreach ($args as $a) {
            //match --extends
            if (substr($a, 0, strlen("--extends=")) == "--extends=") {
                $this->extends = explode("=", $a);
                $this->extends = $this->extends[1];
                continue;
            }

            if ($a == "--no-factory") {
                $this->createFactory = false;
                continue;
            }

            if (substr($a, 0, strlen("--test=")) == "--test=") {
                $this->test = explode("=", $a)[1];
                continue;
            }
        }
    }
1189977
public function mergeArgsAndParams(array $args, array $params = null)
    {

        if ($params) {
            foreach ($args as &$arg) {
                if (is_array($arg)) {
                    foreach ($params as &$param) {
                        if (is_array($param)) {
                            $arg = $param;
                            unset($param);
                            break;
                        }
                    }
                }
            }
        }

        if (is_array($params)) {
            return array_merge($args, $params);
        }

        return $args;
    }
820234
public function validate(Args $args) {
        $isValid = true;
        $command = $args->getCommand();
        $valid = new Args($command);
        $schema = $this->getSchema($command);
        ksort($schema);

//        $meta = $schema[Cli::META];
        unset($schema[Cli::META]);
        $opts = $args->getOpts();
        $missing = [];

        // Check to see if the command is correct.
        if ($command && !$this->hasCommand($command) && $this->hasCommand()) {
            echo $this->red("Invalid command: $command.".PHP_EOL);
            $isValid = false;
        }

        // Add the args.
        $valid->setArgs($args->getArgs());

        foreach ($schema as $key => $definition) {
            // No Parameter (default)
            $type = Cli::val('type', $definition, 'string');

            if (array_key_exists($key, $opts)) {
                // Check for --key.
                $value = $opts[$key];
                if ($this->validateType($value, $type, $key, $definition)) {
                    $valid->setOpt($key, $value);
                } else {
                    $isValid = false;
                }
                unset($opts[$key]);
            } elseif (isset($definition['short']) && array_key_exists($definition['short'], $opts)) {
                // Check for -s.
                $value = $opts[$definition['short']];
                if ($this->validateType($value, $type, $key, $definition)) {
                    $valid->setOpt($key, $value);
                } else {
                    $isValid = false;
                }
                unset($opts[$definition['short']]);
            } elseif (array_key_exists('no-'.$key, $opts)) {
                // Check for --no-key.
                $value = $opts['no-'.$key];

                if ($type !== 'boolean') {
                    echo $this->red("Cannot apply the --no- prefix on the non boolean --$key.".PHP_EOL);
                    $isValid = false;
                } elseif ($this->validateType($value, $type, $key, $definition)) {
                    $valid->setOpt($key, !$value);
                } else {
                    $isValid = false;
                }
                unset($opts['no-'.$key]);
            } elseif ($definition['required']) {
                // The key was not supplied. Is it required?
                $missing[$key] = true;
                $valid->setOpt($key, false);
            }
        }

        if (count($missing)) {
            $isValid = false;
            foreach ($missing as $key => $v) {
                echo $this->red("Missing required option: $key".PHP_EOL);
            }
        }

        if (count($opts)) {
            $isValid = false;
            foreach ($opts as $key => $v) {
                echo $this->red("Invalid option: $key".PHP_EOL);
            }
        }

        if ($isValid) {
            return $valid;
        } else {
            echo PHP_EOL;
            return null;
        }
    }
276294
protected function validateArgs()
    {
        $message = null;
        foreach ($this->getMandatoryArgs() as $arg) {
            if (!isset($this->args[$arg])) {
                $message = "Argument $arg was not present in supplied job args for job " . get_class($this);
                $this->errorLog($message);
                throw new \Exception($message);
            }
        }
        if ($this->configRequired) {
            $this->ensureConfig();
        }
    }
469593
public function reset_pod( $args, $assoc_args ) {

		$api = pods_api();

		$reset = false;

		try {
			$pod = $api->load_pod( $assoc_args['name'] );

			if ( ! $pod ) {
				WP_CLI::error( sprintf( __( 'Pod "%s" does not exist.', 'pods' ), $assoc_args['name'] ) );
			}

			$reset = $api->reset_pod( $assoc_args );
		} catch ( Exception $e ) {
			WP_CLI::error( sprintf( __( 'Error resetting pod: %s', 'pods' ), $e->getMessage() ) );
		}

		if ( $reset ) {
			WP_CLI::success( __( 'Pod content reset.', 'pods' ) );
		} else {
			WP_CLI::error( __( 'Pod content not reset.', 'pods' ) );
		}

	}
789002
protected function preprocessingArguments(array $argv)
    {
        // preprocessing arguments
        $newArgv = [];
        $extra = [];
        $afterDash = false;
        foreach ($argv as $arg) {
            if ($arg === '--') {
                $afterDash = true;
                continue;
            }
            if ($afterDash) {
                $extra[] = $arg;
                continue;
            }

            $a = new Argument($arg);
            if ($a->anyOfOptions($this->specs) && $a->containsOptionValue()) {
                list($opt, $val) = $a->splitAsOption();
                array_push($newArgv, $opt, $val);
            } else {
                $newArgv[] = $arg;
            }
        }

        return [$newArgv, $extra];
    }
281643
protected void validateArgumentList(String[] args) {
        checkRequiredArguments(args);

        // Skip the first argument as it is the task name
        // Arguments and values come in pairs (expect -password).
        // Anything outside of that pattern is invalid.
        // Loop through, jumping in pairs except when we encounter
        // -password -- that may be an interactive prompt which won't
        // define a value.
        for (int i = 1; i < args.length; i++) {
            String argPair = args[i];
            String arg = null;
            String value = null;
            if (argPair.contains("=")) {
                arg = argPair.split("=")[0];
                value = getValue(argPair);
            } else {
                arg = argPair;
            }

            if (!isKnownArgument(arg)) {
                throw new IllegalArgumentException(getMessage("invalidArg", arg));
            } else {
                if (value == null) {
                    throw new IllegalArgumentException(getMessage("missingValue", arg));
                }
            }
        }
    }
1039181
public function beforeUpdate(&$args) {
        $model = &$args[0];
        $data  = &$args[1];
        $where = &$args[2];
        $this->validate($data, $model, true);
    }
194675
protected function _validateArgs(array $args): bool {
        foreach (self::REQUIRED_FLAGS as $flag) {
            if (!array_key_exists($flag, $args)) {
                Garp_Cli::errorOut("No {$flag} flag provided.");
                return false;
            }
        }
        return true;
    }
301165
protected static function process_csv_arguments_to_arrays( $assoc_args ) {
		foreach ( $assoc_args as $k => $v ) {
			if ( false !== strpos( $k, '__' ) ) {
				$assoc_args[ $k ] = explode( ',', $v );
			}
		}
		return $assoc_args;
	}
365681
public function command($args)
    {
        // Throw if no arguments provided and args less than 2
        if (empty($args) || count($args) < 2) {
            throw new RuntimeException("Invalid argument count");
        }

        $secondArg = $args[1];

        // Output the second argument
        return $secondArg;

    }
314805
public function validate($args)
    {
        $check = $this->normalizeArgs(is_array($args) ? $args : []);

        return is_array($check) ? true : $check;
    }
757892
public function activate( $args, $assoc_args ) {
		\WP_CLI::warning( 'This command is deprecated. use wp site switch-language instead' );

		list( $language_code ) = $args;

		$this->activate_language( $language_code );
	}
275265
public function validate(...$args)
    {
        foreach ($args as $key) {
            $value = $this->getParameter($key);
            if (!isset($value)) {
                throw new InvalidRequestException("The $key parameter is required");
            }
        }
    }
314772
public function spam( $args, $assoc_args ) {
		foreach ( $args as $id ) {
			$this->call( $id, __FUNCTION__, 'Marked as spam', 'Failed marking as spam' );
		}
	}
588743
def _get_extra_args(extra_args, arg_keys):
    
    # XXX back compatible hack -- should have a way to specify these.
    single_keys = set(["sam_ref", "config"])
    out = []
    for i, arg_key in enumerate(arg_keys):
        vals = [xs[i] for xs in extra_args]
        if arg_key in single_keys:
            out.append(vals[-1])
        else:
            out.append(vals)
    return out