parse the argv data and build values

@param array  $argv  An optional array of argv values used for testing.  Leave blank to use the default $_SERVER['argv']

@return ArgumentValues An array-like object that contains switches and data
512186
public function getOptsValues($argv=null) {
    $parsed_args = ArgumentsParser::parseArgvWithSpec($this->resolveArgv($argv), $this->arguments_spec);
    return new ArgumentValues($this->arguments_spec, $parsed_args);
  }
1174977
public function commandFor(array $argv): Command
    {
        $argv += [null, null, null];

        return
             // cmd
            $this->commands[$argv[1]]
            // cmd alias
            ?? $this->commands[$this->aliases[$argv[1]] ?? null]
            // default.
            ?? $this->commands[$this->default];
    }
662195
public function run($argv){

		$isWin = $this->isWindows();

		$output = new \Strukt\Console\Output();
		$output
			->add("\n")
			->add(sprintf(($isWin)?"%s\n%s\n":Color::write("green:bold", "%s\n%s\n"), $this->name, str_repeat("=", strlen($this->name))));
		
		try{

			if(empty(@$argv[1]))
				$argv[1] = "-h";

			$switches = array("-h", "--help", "-l", "--list");
			$allow = array_merge(array_keys($this->commands), $switches);
			$allow = array_filter($allow, function($var){

				if(!is_numeric($var))
					return $var;
			});

			if(!in_array(@$argv[1], $allow))
				throw new \Exception("Command does not exists!");

			switch(@$argv[1]){

				case "--list":
				case "-l":
					$output->add("\n");
					foreach($this->commands as $key=>$command)
						if(is_string($command))
							$output->add($command); 
						elseif(!$command["object"] instanceof \Strukt\Console\Command\Console)
							$output->add(sprintf(($isWin)?"%s %s\n":sprintf(" %s %s\n", 
																		Color::write("skyblue:bold", "%s"), 
																		Color::write("light-blue:bold", "%s")), 
											str_pad($command["doclist"]["command"]["alias"], $this->padlen), 
											$command["doclist"]["command"]["descr"]));
						

				break;
				case "--help":
				case "-h":
					$command = reset($this->commands);
					if(in_array(@$argv[1], $command["doclist"]["aliases"]) ||
						in_array(@$argv[1], array_keys($command["doclist"]["aliases"])))
							$output->add(sprintf(($isWin)?"%s\n":Color::write("light-yellow:bold", "%s"), $command["docparser"]->getBlock()));
				break;
				default:
					$command = $this->commands[@$argv[1]];
					$askHelp = in_array(@$argv[2], array("-h", "--help"));

					if($askHelp)
						$output->add(sprintf(($isWin)?"%s\n":Color::write("light-cyan:bold", "%s"), $command["docparser"]->getBlock()));
					
					if(!$askHelp){

						$input = new \Strukt\Console\Input($argv, $command["docparser"]);
						$input->getInputs();

						$command["object"]->execute($input, $output);
					}
				break;
			}
		}
		catch(\Exception $e){

			return sprintf(($isWin)?"%s\n":Color::writeln("bg-red:bold", "%s"), $e->getMessage());
		}

		if(!$output->isEmpty())
			return $output->add("\n")->write();
	}
1314902
public function parse_query_args( $args ) {
		$query_args = [
			'frontend' => $args,
			'backend'  => $args,
		];

		if ( isset( $args['frontend'] ) || isset( $args['backend'] ) ) {
			foreach ( [ 'frontend', 'backend' ] as $query_type ) {
				$query_args[ $query_type ] = isset( $args[ $query_type ] )
					? $args[ $query_type ]
					: [];
			}
		}

		return $query_args;
	}
296062
public static function getArgv(): array
    {
        if (PHP_SAPI != 'cli') {
            throw new CliException('Can not get $argv because script is not called from CLI');
        }

        if (static::$argv !== null) {
            return static::$argv;
        }

        global $argv;

        if (!isset($argv) || !is_array($argv)) {
            throw new CliException('Can not access the $argv variable. You\'re probably not in the CLI env.');
        }

        static::$argv = $argv;
        return static::$argv;
    }
266660
private function _get_value($args){
    if ( $this->id ){
      $var =& $this->data;
      foreach ( $args as $a ){
        if ( !isset($var[$a]) ){
          return null;
        }
        $var =& $var[$a];
      }
      return $var;
    }
  }
79020
protected function parseAttributes( array $args )
	{
		if( empty( $args['attributes'] )) {
			return [];
		}

		$attributes = (array) $args['attributes'];

		foreach( $attributes as $key => $value ) {
			if( is_string( $key ))continue;
			unset( $attributes[ $key ] );
			if( !isset( $attributes[ $value ] )) {
				$attributes[ $value ] = '';
			}
		}

		return $attributes;
	}
39300
public function parseParams($argv)
    {
        if (is_string($argv)) {
            $argv = gplcart_string_explode_whitespace($argv);
        }

        array_shift($argv);

        $out = array();
        for ($i = 0, $j = count($argv); $i < $j; $i++) {

            $key = null;
            $arg = $argv[$i];

            if (substr($arg, 0, 2) === '--') {

                $pos = strpos($arg, '=');

                if ($pos === false) {
                    $key = substr($arg, 2);
                    if ($i + 1 < $j && $argv[$i + 1][0] !== '-') {
                        $value = $argv[$i + 1];
                        $i++;
                    } else {
                        $value = isset($out[$key]) ? $out[$key] : true;
                    }

                    $out[$key] = $value;
                    continue;
                }

                $key = substr($arg, 2, $pos - 2);
                $value = substr($arg, $pos + 1);
                $out[$key] = $value;
                continue;
            }

            if (substr($arg, 0, 1) === '-') {

                if (substr($arg, 2, 1) === '=') {
                    $key = substr($arg, 1, 1);
                    $value = substr($arg, 3);
                    $out[$key] = $value;
                    continue;
                }

                foreach (str_split(substr($arg, 1)) as $char) {
                    $key = $char;
                    $value = isset($out[$key]) ? $out[$key] : true;
                    $out[$key] = $value;
                }

                if ($i + 1 < $j && $argv[$i + 1][0] !== '-') {
                    $out[$key] = $argv[$i + 1];
                    $i++;
                }

                continue;
            }

            $value = $arg;
            $out[] = $value;
        }

        return $out;
    }
871051
public static function parse(array $arguments):array
    {
        if (count($arguments) < 1) {
            throw new Server500(new \ArrayObject(array("explain" => "Cannot parse value without commands",
                "solution" => "Please set an command to parse it")));
        }
        $exec = self::parseExecutable($arguments);

        if (isset($arguments[0])) {
            unset($arguments[0]);
        }

        $com = self::parseCommands($arguments);
        $opt = self::parseOptions($arguments);

        return (["global" => $exec, "commands" => $com, "options" => $opt]);
    }
515806
public static function arguments(array $args) : array
    {
        putenv("CODGER_DRY=1");
        foreach ($args as $key => $value) {
            if ($value === '-w') {
                putenv("CODGER_DRY=0");
                unset($args[$key]);
            }
            if ($value === '-o') {
                putenv("CODGER_OVERWRITE=1");
                putenv("CODGER_DRY=0");
                unset($args[$key]);
            }
            if ($value === '-d') {
                putenv("CODGER_OVERWRITE=0");
                putenv("CODGER_DUMP=1");
                putenv("CODGER_DRY=0");
                unset($args[$key]);
            }
            if ($value === '-s') {
                putenv("CODGER_OVERWRITE=0");
                putenv("CODGER_SKIP=1");
                putenv("CODGER_DRY=0");
                unset($args[$key]);
            }
        }
        return array_values($args);
    }
1207947
private function readPHPArgv()
    {
        global $argv;
        if (!is_array($argv)) {
            if (!@is_array($_SERVER['argv'])) {
                if (!@is_array($GLOBALS['HTTP_SERVER_VARS']['argv'])) {
                    throw new Exception(
                        "Could not read cmd args (register_argc_argv=Off?)",
                        Exception::E_ARG_READ
                    );
                }
                return $GLOBALS['HTTP_SERVER_VARS']['argv'];
            }
            return $_SERVER['argv'];
        }
        return $argv;
    }
1125589
public function parse($argv, $override = true)
    {
        $exists = [];
        $override ? $this->_values = $this->_defaults : $exists = array_fill_keys(array_keys($this->_values), true);

        foreach ($argv as $arg) {
            if ($arg === '--') {
                break;
            }
            if ($arg[0] === '-') {
                list($name, $value) = $this->_parse(ltrim($arg, '-'));
                if ($override || !isset($exists[$name])) {
                    $this->add($name, $value);
                }
            }
        }

        return $this->get();
    }
650901
private function parseArgs(array $args)
    {
        if (! count($args)) {
            return $this->createHelpArgument();
        }

        $arg1 = array_shift($args);

        if (in_array($arg1, ['-h', '--help', 'help'], true)) {
            return $this->createHelpArgument();
        }

        if (! count($args)) {
            return $this->createErrorArgument('Missing class name');
        }

        $configFile = $arg1;
        switch (file_exists($configFile)) {
            case true:
                $config = require $configFile;

                if (! is_array($config)) {
                    return $this->createErrorArgument(sprintf(
                        'Configuration at path "%s" does not return an array.',
                        $configFile
                    ));
                }

                break;
            case false:
                // fall-through
            default:
                if (! is_writable(dirname($configFile))) {
                    return $this->createErrorArgument(sprintf(
                        'Cannot create configuration at path "%s"; not writable.',
                        $configFile
                    ));
                }

                $config = [];
                break;
        }

        $class = array_shift($args);

        if (! class_exists($class)) {
            return $this->createErrorArgument(sprintf(
                'Class "%s" does not exist or could not be autoloaded.',
                $class
            ));
        }

        return $this->createArguments(self::COMMAND_DUMP, $configFile, $config, $class);
    }
836748
public function run(array $argv, ConsoleIo $io)
    {
        $this->initialize();

        $parser = $this->getOptionParser();
        try {
            list($options, $arguments) = $parser->parse($argv);
            $args = new Arguments(
                $arguments,
                $options,
                $parser->argumentNames()
            );
        } catch (ConsoleException $e) {
            $io->err('Error: ' . $e->getMessage());

            return static::CODE_ERROR;
        }
        $this->setOutputLevel($args, $io);

        if ($args->getOption('help')) {
            $this->displayHelp($parser, $args, $io);

            return static::CODE_SUCCESS;
        }

        return $this->execute($args, $io);
    }
191231
private function _parseArgs(array $args)
	{
		$arg = '';
		if(count($args) > 0)
		{
			foreach($args as $number => $argument)
			{
				if($number === 0)
				{
					$arg .= $argument;
				}
				else
				{
					$arg .= ', ' . $argument;
				}
			}
		}

		return $arg;
	}
30010
public function parse($arguments = null)
    {
        $this->_options = [];
        $this->_values = [];

        if ($arguments === null) {
            if (isset($GLOBALS['argv'][1]) && $GLOBALS['argv'][1][0] === '/') {
                $arguments = [$GLOBALS['argv'][1]];
            } else {
                /** @noinspection CallableParameterUseCaseInTypeContextInspection */
                $arguments = array_slice($GLOBALS['argv'], 3);
            }
        }

        if (count($arguments) === 1 && $arguments[0][0] === '/') {
            $query = parse_url($arguments[0], PHP_URL_QUERY);
            parse_str($query, $this->_options);
            if (($fragment = parse_url($arguments[0], PHP_URL_FRAGMENT)) !== null) {
                $this->_values[] = $fragment;
            }
        } else {
            $this->_parse($arguments);
        }

        return $this;
    }
32767
public function getArgs(int $argc, array $argv)
    {
        if ($argc == 1) {
            Output::displayAsGreen(
                "Welcome to the Framework Console Manager\n".
                "I noticed that you didn't enter any parameters.\n".
                "For more information, you can use the help command to get a command list."
            );
        }

        $c = $this->searchCommand($argv[1]);
        if (empty($c)) {
            CoreManager::setCurrentModule("Error");
            $predict = (PredictionManager::parsePredict($argv[1]));
            if (empty($predict)) {
                Output::displayAsError("Command not found.\n".
                    "For more information, you can use the [help] command to get a command list.");
            } else {
                Output::displayAsError("Input [".$argv[1]."] is ambigus.\n".
                    "To get command list, use [help] keyword.\n\n".
                    PredictionManager::structMessage($predict));
            }
        }

        $p = ParseManager::parse($argv);
        $ref = new Reflex();
        $ref->__simple($c['class'], $p);
    }