public static function readCliArguments(array $argv, CliScriptInterface $cli_interface) { ////Read in flags first. //Get flag options (I'm being annoying here so the flags from this file over ride any others but still display last.) $cli_options = CliScriptAbstract::$script_cli_options + array_reverse($cli_interface->getCliOptions()); $cli_options = array_reverse($cli_options); //read in, save, then remove flags from argv. $argv = CliScriptAbstract::processFlags($argv, $cli_options, CliScriptAbstract::getFlagModifications($cli_interface)); //make the flags easier to access here by giving them local scope. extract(CliScriptAbstract::$flags); //Read in all other vars. $cli_description = $cli_interface->getCliDescription(); $cli_params = $cli_interface->getCliParameters(); $cli_extras = $cli_interface->getOtherInputsDescription(); //I want the full help menu to have precedence over the brief window. if (!$isRun && (count($argv) == 1 || $isHelp)) { CliScriptAbstract::print_help($cli_description, $cli_params, $cli_options, $cli_extras); die("\n"); } else { if (!$isRun && ($isBriefHelp || $isBashHelp)) { $brief = $isBriefHelp ? "brief" : "bash"; CliScriptAbstract::print_help($cli_description, $cli_params, $cli_options, $cli_extras, $brief); die("\n"); } } //Past the help Menu, lets read in some vars $vars = array(); //Named Vars sent through in the config as expected $flags = array(); //Flags sent through in the config as expected $wildcards = array(); //Named vars that were not expected $other_inputs = array(); //Catch all for other input. $exploded_args = array(); foreach ($argv as $arg) { if (strpos($arg, "=") !== FALSE) { $e = explode("=", $arg); $param_key = $e[0]; if ($e[1][0] == "{") { $e[1] = CliScriptAbstract::convertSmartQuotes($e[1]); $exploded_args[$param_key] = json_decode($e[1], true); if (json_last_error() !== JSON_ERROR_NONE) { CliScriptAbstract::$last_error = $e[0]; CliScriptAbstract::confirm("JSON Object, " . $e[0] . ", was not successfully decoded: " . json_last_error_msg() . "\nContinue anyway?", "Try 'http://www.jsoneditoronline.org/' if you don't know what is wrong."); unset($exploded_args[$param_key]); } } else { if (strpos($e[1], "(string)") !== false) { $exploded_args[$param_key] = substr($e[1], 0, -8); } else { if (is_numeric($e[1])) { $exploded_args[$param_key] = $e[1] + 0; } else { $exploded_args[$param_key] = $e[1]; } } } } else { array_push($other_inputs, $arg); } } foreach ($cli_params as $param_var => $rest) { if (isset($exploded_args[$rest[0]])) { $vars[$param_var] = $exploded_args[$rest[0]]; unset($exploded_args[$rest[0]]); } } CliScriptAbstract::processVars($exploded_args, $cli_params); return array("config_vars" => $vars, "wildcard_vars" => $exploded_args, "other_inputs" => $other_inputs); }
public function convertSmartQuotes($string) { return CliScriptAbstract::convertSmartQuotes($string); }