You are here

function get_opt in Gutenberg 8.2

Process the options.

Use custom argument getter.

Return value

array The argument options.

1 call to get_opt()
_cli_include.inc.php in scripts/_cli_include.inc.php

File

scripts/_cli_include.inc.php, line 25

Code

function get_opt() {
  global $argv, $argc, $_POSITIONAL_ARGS;
  $options = [];
  for ($i = 1; $i < $argc; $i++) {
    $arg = $argv[$i];
    if (strlen($arg) > 1 && $arg[0] === '-') {
      if ($arg[1] === '-') {
        if (strpos($arg, '=')) {

          /* Argument like --database=value */
          $explode = explode('=', $arg);
          $options[substr($explode[0], 2)] = $explode[1];
        }
        elseif ($i + 1 === $argc || $argv[$i + 1][0] === '-') {

          /* Argument like --flag */
          $options[substr($arg, 2)] = TRUE;
        }
        else {

          /* Argument like --database value */
          $i++;
          $options[substr($arg, 2, strlen($arg))] = $argv[$i];
        }
      }
      else {

        // Short argument.
        $options[$arg[1]] = substr($arg, 2, strlen($arg));
      }
    }
    else {
      $_POSITIONAL_ARGS[] = $arg;
    }
  }
  return $options;
}