Parse a short argument that is prefixed with a single dash '-'

@param $command
@param $arguments
@param $argPointer
@throws InvalidValueException
@throws InvalidArgumentException
428729
private function parseShortArgument($command, $arguments, &$argPointer, &$output)
    {
        $argument = $arguments[$argPointer];
        $option = $this->retrieveOptionFromCache($command, substr($argument, 1, 1));
        $value = true;

        if (isset($option['type'])) {
            if (substr($argument, 2) != "") {
                $value = substr($argument, 2);
            } else {
                $value = $this->getNextValueOrFail($arguments, $argPointer, $option['name']);
            }
        }

        $this->assignValue($option, $output, $option['name'], $value);
    }
876281
protected function getKeyFromBlockingListCommands(string $command, array $arguments)
    {
        if ($this->checkSameSlotForKeys(\array_slice($arguments, 0, \count($arguments) - 1))) {
            return $arguments[0];
        }

        return null;
    }
60331
public function handle(CommandInterface $command)
    {
        if (!$this->supports(get_class($command))) {
            throw new InvalidArgumentException(
                sprintf(
                    'The command must be an instance of "%s". "%s" given.',
                    $this->getSupportedCommandClassName(),
                    get_class($command)
                )
            );
        }

        return $this->execute($command);
    }
725005
private function parseInput($argv)
    {
        if ($argv === null || ($match = $this->findOption('help', 'h', $argv)) !== false) {
            $this->input['help'] = true;
            return;
        }

        if (($match = $this->findOption('verbose', 'v', $argv)) !== false) {
            if (empty($match[1]) && $match[1] !== '0') {
                throw new InvalidArgumentException('Value for option "verbose" expected.');
            }
            $this->stdio->setVerbosity($match[1]);
            unset($argv[$match[0]]);
        }

        // parse the arguments
        foreach ($this->arguments as $key => $def) {
            if (isset($argv[0]) && $argv[0][0] != '-') {
                $value = array_shift($argv);
                $this->input[$key] = $this->cast($value, $def['type']);
            }
            else {
                if (!array_key_exists('default', $def)) {
                    throw new InvalidArgumentException('Argument "' . $key . '"" is required.');
                }
                $this->input[$key] = $def['default'];
            }
        }

        // parse the options
        foreach ($this->options as $key => $def) {
            if (($match = $this->findOption($key, isset($def['short']) ? $def['short'] : null, $argv)) !== false) {
                list($i, $value) = $match;
                if ($value !== null) {
                    // option with value
                    if ($def['type'] == 'bool') {
                        throw new InvalidArgumentException('Value for option "' . $key . '"" does not expected.');
                    }
                    if ($value !== '') {
                        $this->input[$key] = $this->cast($value, $def['type']);
                    }
                    else {
                        $this->input[$key] = isset($def['default']) ? $def['default'] : null;
                    }
                }
                else {
                    // option without a value
                    if ($def['type'] != 'bool') {
                        throw new InvalidArgumentException('Value for option "' . $key . '"" expected.');
                    }
                    $this->input[$key] = true;
                }
                unset($argv[$i]);
            }
            else {
                $this->input[$key] = $def['type'] == 'bool' ? false : (isset($def['default']) ? $def['default'] : null);
            }
        }

        if (!empty($argv)) {
            throw new InvalidArgumentException('Parameter "' . $argv[0] . '" not expected.');
        }
    }
245337
private function buildCommand($command, $argument)
    {
        $command = sprintf($command, $argument);
        $this->output->writeln(
            'Calling following command:' . "\n" . $command,
            OutputInterface::VERBOSITY_DEBUG
        );

        return $command;
    }
1123938
private function getCommandString($command, array $arguments)
    {
        $list = array();
        $this->flatten($arguments, $list);

        return trim(strtoupper($command).' '.implode(' ', $list));
    }
595072
protected function getKeyFromInterleavedArguments(CommandInterface $command)
    {
        $arguments = $command->getArguments();
        $keys = array();

        for ($i = 0; $i < count($arguments); $i += 2) {
            $keys[] = $arguments[$i];
        }

        if ($this->checkSameSlotForKeys($keys)) {
            return $arguments[0];
        }
    }
386481
private function getResult($command, $args, $fixArgs = false, $returnRaw = false)
    {
        $cmd = $this->getCommand($command, $args);

        // Marketo expects parameter arrays in the format id=1&id=2, Guzzle formats them as id[0]=1&id[1]=2.
        // Use a quick regex to fix it where necessary.
        if ($fixArgs) {
            $cmd->prepare();

            $url = preg_replace('/id%5B([0-9]+)%5D/', 'id', $cmd->getRequest()->getUrl());
            $cmd->getRequest()->setUrl($url);
        }

        $cmd->prepare();

        if ($returnRaw) {
            return $cmd->getResponse()->getBody(true);
        }

        return $cmd->getResult();
    }
349768
public function add_command($command)
    {
        if (is_string($command)) {
            $command = (new \ReflectionClass($command))->newInstance(self::$CI);
        }

        if (!$command instanceof Commands) {
            throw new \InvalidArgumentException(
                sprintf(
                    'Argument 1 passed to %s must be an instance of %s, %s given',
                    __NAMESPACE__ . '\Cli::add_command()',
                    __NAMESPACE__ . '\Commands',
                    gettype($command)
                )
            );
        }

        $this->commands[$command->name()] = $command;
    }
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
        ];
    }
387792
public function callCommand(string $command, array $arguments = [])
    {
        $newCommand = $this->getApplication()->find($command);

        $arguments['command'] = $command;

        return $newCommand->run(new ArrayInput($arguments), $this->getOutput());
    }
660436
protected function getKeyFromGeoradiusCommands(string $command, array $arguments)
    {
        $argc = \count($arguments);
        $startIndex = $command === 'GEORADIUS' ? 5 : 4;

        if ($argc > $startIndex) {
            $keys = [$arguments[0]];

            for ($i = $startIndex; $i < $argc; ++$i) {
                $argument = \strtoupper($arguments[$i]);
                if ($argument === 'STORE' || $argument === 'STOREDIST') {
                    $keys[] = $arguments[++$i];
                }
            }

            if ($this->checkSameSlotForKeys($keys)) {
                return $arguments[0];
            }

            return null;
        }

        return $arguments[0];
    }
254013
public function add($command)
    {
        if (is_string($command)) {
            $command = new $command($this->container);
        }

        if (!$command instanceof Console\Commands) {
            throw new \InvalidArgumentException(
                sprintf(
                    'Argument 1 passed to %s must be an instance of %s, %s given',
                    __FUNCTION__,
                    Console\Commands::class,
                    get_class($command)
                )
            );
        }

        if (array_key_exists($command->name(), $this->commands)) {
            throw new \RuntimeException(
                sprintf('Command %s already registered', $command->name())
            );
        }

        $this->commands[$command->name()] = $command;

        return $this;
    }
690373
public void parseArgsNoExit(String[] args) throws ParseException {
        // Parse command line.
        CommandLine cmd = null;
        CommandLineParser parser = new PosixParser();
        cmd = parser.parse(options, args);

        // Special handling of --flagfile.
        if (cmd.hasOption(flagfileOpt.getLongOpt())) {
            String value = cmd.getOptionValue(flagfileOpt.getLongOpt());
            String[] ffArgs = readFlagFile(value);
            parseArgs(ffArgs);
        }
        
        // Process each flag mapped to a field.
        fieldValueMap = new HashMap<>();
        try {
            for (Option apacheOpt : optionFieldMap.keySet()) {
                Field field = optionFieldMap.get(apacheOpt);
                if (cmd.hasOption(apacheOpt.getLongOpt())) {
                    String value = apacheOpt.hasArg() ? cmd.getOptionValue(apacheOpt.getLongOpt()) : "true";
                    if (Modifier.isStatic(field.getModifiers())) {
                        // For static fields, set the value directly to the field.
                        setStaticField(field, value);
                    } else {
                        // For non-static fields, cache the value for later use by getInstanceFromParsedArgs(). 
                        fieldValueMap.put(field, value);
                    }
                }
            }
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        }
    }
255823
protected function compileArguments(ICommand $command, IRequest $request)
    {
        $argumentValues = $request->getArgumentValues();
        $commandArguments = $command->getArguments();

        if ($this->hasTooManyArguments($argumentValues, $commandArguments)) {
            throw new RuntimeException('Too many arguments');
        }

        $hasSetArrayArgument = false;

        foreach ($commandArguments as $argument) {
            if (count($argumentValues) === 0) {
                if (!$argument->isOptional()) {
                    throw new RuntimeException("Argument \"{$argument->getName()}\" does not have default value");
                }

                $command->setArgumentValue($argument->getName(), $argument->getDefaultValue());
            } else {
                if ($hasSetArrayArgument) {
                    throw new RuntimeException('Array argument must appear at end of list of arguments');
                }

                if ($argument->isArray()) {
                    // Add the rest of the values in the request to this argument
                    $restOfArgumentValues = [];

                    while (count($argumentValues) > 0) {
                        $restOfArgumentValues[] = array_shift($argumentValues);
                    }

                    $command->setArgumentValue($argument->getName(), $restOfArgumentValues);
                    $hasSetArrayArgument = true;
                } else {
                    $command->setArgumentValue($argument->getName(), array_shift($argumentValues));
                }
            }
        }
    }
233120
protected function getKeyFromScriptingCommands(string $command, array $arguments)
    {
        $keys = \array_slice($arguments, 2, $arguments[1]);

        if ($keys && $this->checkSameSlotForKeys($keys)) {
            return $keys[0];
        }

        return null;
    }
1016476
protected function parse($command, array $arguments = array(), $output)
    {
        if (null !== $this->parser) {
            return $this->parser->parse($command, $arguments, $output);
        }

        return $output;
    }