Parse unset command line options into non-prefixed CLImate arguments.

Non-prefixed arguments are parsed after the prefixed arguments on the
command line, in the order that they're defined in the script.

@param array $unParsedArguments
558855
protected function nonPrefixedArguments(array $unParsedArguments = [])
    {
        foreach ($this->filter->withoutPrefix() as $key => $argument) {
            if (isset($unParsedArguments[$key])) {
                $argument->setValue($unParsedArguments[$key]);
            }
        }
    }
763849
private function _resolveArgs(array $args)
        {
            $resolved = array();
            foreach ($args as $argDefinition) {
                switch ($argDefinition['type']) {
                    case 'lookup':
                        $resolved[] = $this->_lookupRecursive($argDefinition['item']);
                        break;
                    case 'value':
                        $resolved[] = $argDefinition['item'];
                        break;
                }
            }

            return $resolved;
        }
358974
protected function processArguments(array $args) {
		$definition = [];
		
		foreach ($args as $arg) {
			if ($arg->getName() !== 'argument') {
				throw new InvalidConfig('Unknown element "' . $arg->getName() . '" in arguments definition', null, null, $arg);
			}

			$definition[] = $this->processArgument($arg);
		}
		
		return $definition;
	}
999865
public static function removeDefaultArguments(&$arguments)
    {
        foreach ($arguments as $key => $argument) {
            if ($argument === self::DEFAULT_ARGUMENT) {
                unset($arguments[$key]);
            }
        }
    }
864418
public function evaluateArgs(array $args) : void
    {
        array_shift($args);

        if (count($args) < 2) {
            $this->out->red("Not enough arguments: expects 2, got ".(count($args) - 1).".");
            return;
        }

        $this->setName($args[0]);
        $this->setLocation($args[1]);
        if (isset($args[2])) {
            $this->additionalArgs(array_slice($args, 2, count($args)));
        }

        return;
    }
56784
private function hasTooManyArguments(array $argumentValues, array $commandArguments) : bool
    {
        if (count($argumentValues) > count($commandArguments)) {
            // Only when the last argument is an array do we allow more request arguments than command arguments
            if (count($commandArguments) === 0 || !end($commandArguments)->isArray()) {
                return true;
            }
        }

        return false;
    }
661965
protected function parseRelationParameters(array $unparsed): array
    {
        $parseRelationParameters = [];
        $modelNamespace = \Phalcon\Di::getDefault()->getConfig()->namespace->models;

        foreach ($unparsed as $model => $query) {
            $modelName = str_replace(' ', '', ucwords(str_replace('_', ' ', $model)));
            $modelName = $modelNamespace . '\\' . $modelName;

            if (!class_exists($modelName)) {
                throw new \Exception('Related model does not exist.');
            }

            $parseRelationParameters[$modelName] = $this->parseSearchParameters($query)['mapped'];
        }

        return $parseRelationParameters;
    }
1280527
protected function normalizeArgs(array $args)
    {
        $args += [
            'statsFromPackage' => '',
        ];
        $error = $this->app->make('helper/validation/error');
        $normalized = [];

        try {
            /* @var \CommunityTranslation\Service\RateLimit $rateLimitHelper */
            list($normalized['rateLimit_maxRequests'], $normalized['rateLimit_timeWindow']) = $this->app->make(RateLimit::class)->fromWidgetHtml('rateLimit', $this->rateLimit_timeWindow ?: 3600);
        } catch (UserMessageException $x) {
            $error->add($x->getMessage());
        }

        $normalized['maxFileSize'] = null;
        if (isset($args['maxFileSizeValue']) && (is_int($args['maxFileSizeValue']) || (is_string($args['maxFileSizeValue']) && is_numeric($args['maxFileSizeValue'])))) {
            $maxFileSizeValue = (int) $args['maxFileSizeValue'];
            if ($maxFileSizeValue > 0) {
                $maxFileSizeUnit = $this->post('maxFileSizeUnit');
                $p = is_string($maxFileSizeUnit) ? array_search($maxFileSizeUnit, ['b', 'KB', 'MB', 'GB'], true) : false;
                if ($p === false) {
                    $error->add(t('Please specify the unit of the max size of uploaded files'));
                } else {
                    $maxFileSize = (int) $maxFileSizeValue * pow(1024, $p);
                    $postLimit = $this->getPostLimit();
                    if ($postLimit !== null && $maxFileSize > $postLimit) {
                        $nh = $this->app->make('helper/number');
                        $error->add(
                            t(
                                'You can\'t set the max file size to %1$s since the current limit imposed by PHP is %2$s',
                                $nh->formatSize($maxFileSize),
                                $nh->formatSize($postLimit)
                            )
                        );
                    } else {
                        $normalized['maxFileSize'] = $maxFileSize;
                    }
                }
            }
        }
        $normalized['maxLocalesCount'] = null;
        if (isset($args['maxLocalesCount']) && (is_int($args['maxLocalesCount']) || (is_string($args['maxLocalesCount']) && is_numeric($args['maxLocalesCount'])))) {
            $i = (int) $args['maxLocalesCount'];
            if ($i > 0) {
                $normalized['maxLocalesCount'] = $i;
            }
        }
        $normalized['maxStringsCount'] = null;
        if (isset($args['maxStringsCount']) && (is_int($args['maxStringsCount']) || (is_string($args['maxStringsCount']) && is_numeric($args['maxStringsCount'])))) {
            $i = (int) $args['maxStringsCount'];
            if ($i > 0) {
                $normalized['maxStringsCount'] = $i;
            }
        }
        $normalized['statsFromPackage'] = '';
        if (is_string($args['statsFromPackage'])) {
            $normalized['statsFromPackage'] = trim($args['statsFromPackage']);
            if ($normalized['statsFromPackage'] !== '') {
                $package = $this->app->make(PackageRepository::class)->findOneBy(['handle' => $normalized['statsFromPackage']]);
                if ($package === null) {
                    $error->add(t('Unable to find a package with handle "%s"', $normalized['statsFromPackage']));
                } elseif ($package->getLatestVersion() === null) {
                    $error->add(t('The package with handle "%s" does not have a latest version', $normalized['statsFromPackage']));
                }
            }
        }

        return $error->has() ? $error : $normalized;
    }
1005163
private static function parseCommands(array $arguments):array
    {
        $commands = [];
        foreach ($arguments as $one) {
            if (strpos($one, '--') === false) {
                $commands[] = $one;
            }
        }
        return ($commands);
    }
100907
private function resolveArgs(array $args)
    {
        $resolved = [];
        foreach ($args as $argDefinition) {
            switch ($argDefinition['type']) {
                case 'lookup':
                    $resolved[] = $this->lookupRecursive($argDefinition['item']);
                    break;
                case 'value':
                    $resolved[] = $argDefinition['item'];
                    break;
            }
        }

        return $resolved;
    }
50667
private void parseCommandLineArgs(String[] args) throws ConfigurationException {
        if (args == null || args.length == 0) {
            return;
        }
        logger.info("Parsing command line arguments");
        m_commandLineArgs = args;
        
        try {
            for (int inx = 0; inx < args.length; inx++) {
                String arg = args[inx];
                if (arg.equals("-?") || arg.equalsIgnoreCase("-h") || arg.equalsIgnoreCase("-help")) {
                    System.out.println("See documentation and doradus.yaml for help.");
                    System.exit(0);
                }
                Utils.require(arg.charAt(0) == '-', "Unrecognized argument: %s", arg);
                Utils.require(inx + 1 < args.length, "A value is expected after: %s", arg);
                String name = arg.substring(1);
                String value = args[++inx];
                setCommandLineParam(name, value);
            }
        } catch (Exception e) {
            logger.error("Failed to parse command line arguments", e);
            throw new ConfigurationException("Failed to parse command line arguments", e);
        }
    }
1260290
protected function getArgumentsFromParams($params)
    {
        $args     = array();
        $excludes = array("name", "before", "separator", "after", "fields");

        if (is_array($params)) {
            foreach ($params as $key => $value) {
                if (!in_array($key, $excludes)) {
                    $args[$key] = $value;
                }
            }
        }

        return $args;
    }
785273
public function invokeArguments(array $arguments)
    {
        $parsedArguments = $this->argumentParser->parse($arguments, $this->getParameters());

        return call_user_func_array($this->callable, $parsedArguments);
    }
122600
private function parseArgs($args) {
        $command = $action = null;
        $params = [];
        foreach ($args as $argument) {
            if ('-' != $argument[0])
                if (null === $command)
                    $command = $argument;
                elseif (null === $action)
                    $action = $argument;
                else
                    $this->alert('Invalid argument ' . $argument . '!', ['command' => $command, 'action' => $action, 'serverArguments' => $_SERVER['argv'], 'processedArguments' => $args]);
            else {
                $argument = substr($argument, 1); // supports both  one - or two - ( - / -- )
                if ('-' == $argument[0])
                    $argument = substr($argument, 1);

                $argument = explode('=', $argument, 2);
                $params[$argument[0]] = isset($argument[1]) ? $argument[1] : true;
            }
        }
        return [
            'command' => $command,
            'action' => $action,
            'params' => $params
        ];
    }
1283750
public function removeArguments(array $arguments = null)
  {
    if ($this->isLocked()) {
      return $this->getObj()->removeArguments($arguments)->setLocked();
    } else {
      return parent::removeArguments($arguments);
    }
  }
492427
private function parse_args($args = [])
    {
        $args['NAMESPACE'] = '';

        $class_name = $this->sanitise_filename($args['CLASSNAME']);

        if ($this->is_nested_directory($class_name)) {
            $parts = \explode('\\', $class_name);
            $class = \array_pop($parts);

            $args['NAMESPACE'] = '\\' . \implode('\\', $parts);
            $args['CLASSNAME'] = $class;
        }

        return $args;
    }
1088800
static public String unparseTokens(final List<ICmdLineArg<?>> args)
    {
        final StringBuilder out = new StringBuilder();
        unparseTokens("", args, out);
        return out.toString();
    }