Parse options given on the command line, and merge them
with the existing options.

@param array $opts The options to merge with

@return array
970118
private function parseCliOptions(array $opts = [])
    {
        $cliOpts = getopt('chvrs:', [
            'help',
            'version',
            'random',
            'suite:',
            'coverage',
        ]);

        if (isset($cliOpts['help']) || isset($cliOpts['h'])) {
            $this->runner->output->help();
            exit;
        }

        if (isset($cliOpts['version']) || isset($cliOpts['v'])) {
            $this->runner->output->version();
            exit;
        }

        if (isset($cliOpts['random']) || isset($cliOpts['r'])) {
            $opts['random'] = true;
        }

        if (isset($cliOpts['suite']) || isset($cliOpts['s'])) {
            $opts['suite'] = $cliOpts['suite'] ?: $cliOpts['s'];
        }

        if (isset($cliOpts['coverage']) || isset($cliOpts['c'])) {
            $opts['coverage']['enable'] = true;
        }

        return $opts;
    }
544643
public function read(array $opts) {
        return [array_merge(parent::read($opts)[0], [
            'recipe' => 'scorm_event',
            'scorm_url' => $opts['module']->url,
            'scorm_name' => $opts['module']->name,
            'scorm_scoes_id' => $opts['scorm_scoes']->id,
            'scorm_scoes_type' => 'http://adlnet.gov/expapi/activities/lesson',
            'scorm_scoes_url' => $opts['module']->url,
            'scorm_scoes_name' => $opts['scorm_scoes']->title,
            'scorm_scoes_description' => $opts['scorm_scoes']->title,
            'scorm_attempt' => $opts['cmi_data']['attemptid'],
            'scorm_status' => $opts['scorm_scoes_track']['status'],
        ])];
    }
348910
public function read(array $opts) {

        $sessionName = 'Session '.$opts['session']->id.' of '.$opts['module']->name;
        return [array_merge(parent::read($opts)[0], [
            'recipe' => 'training_session_enrol',
            'session_url' => $opts['session']->url,
            'session_name' => $sessionName,
            'session_description' => $sessionName,
            'session_type' => 'http://activitystrea.ms/schema/1.0/event',
        ])];
    }
1330209
public function getChoices($opts = [])
    {
        $include_blank_dash = (array_key_exists('include_blank', $opts)) ?
            false == $opts['include_blank'] : true;

        $first_choice = [];
        if ($include_blank_dash) {
            $first_choice = self::BLANK_CHOICE_DASH;
        }

        if (!empty($this->choices)) {
            return array_merge($first_choice, $this->choices);
        }

        // load from relationships todo
    }
12641
private function parsePoolOptions($options)
    {
        $defaults = [
            'pool_class' => $this->poolClass,
            'item_class' => $this->itemClass,
            'namespace'  => $this->namespace,
            'logger'     => $this->logger,
        ];

        if ($options === null) {
            return $defaults;
        }

        if (is_string($options)) {
            $options = [
                'namespace' => $options
            ];
        }

        if (!is_array($options)) {
            return $defaults;
        }

        return array_replace($defaults, $options);
    }
951765
public function read(array $opts) {
        return [array_merge(parent::read($opts)[0], [
            'recipe' => 'discussion_viewed',
            'discussion_url' => $opts['discussion']->url,
            'discussion_name' => $opts['discussion']->name,
            'discussion_description' => 'A Moodle discussion.',
            'discussion_type' => static::$xapiType.$opts['discussion']->type,
            'discussion_ext' => $opts['discussion'],
            'discussion_ext_key' => 'http://lrs.learninglocker.net/define/extensions/moodle_discussion',
        ])];
    }
954761
protected static function _parseLongOption($arg, $long_options, &$opts, &$argIdx, $args, $skip_unknown)
    {
        @list($opt, $opt_arg) = explode('=', $arg, 2);

        $opt_len = strlen($opt);

        for ($i = 0; $i < count($long_options); $i++) {
            $long_opt  = $long_options[$i];
            $opt_start = substr($long_opt, 0, $opt_len);

            $long_opt_name = str_replace('=', '', $long_opt);

            /* Option doesn't match. Go on to the next one. */
            if ($long_opt_name != $opt) {
                continue;
            }

            $opt_rest = substr($long_opt, $opt_len);

            /* Check that the options uniquely matches one of the allowed
               options. */
            if ($i + 1 < count($long_options)) {
                $next_option_rest = substr($long_options[$i + 1], $opt_len);
            } else {
                $next_option_rest = '';
            }

            if ($opt_rest != '' && $opt{0} != '=' &&
                $i + 1 < count($long_options) &&
                $opt == substr($long_options[$i+1], 0, $opt_len) &&
                $next_option_rest != '' &&
                $next_option_rest{0} != '=') {

                $msg = "Console_Getopt: option --$opt is ambiguous";
                return PEAR::raiseError($msg);
            }

            if (substr($long_opt, -1) == '=') {
                if (substr($long_opt, -2) != '==') {
                    /* Long option requires an argument.
                       Take the next argument if one wasn't specified. */;
                    if (!strlen($opt_arg)) {
                        if (!isset($args[++$argIdx])) {
                            $msg = "Console_Getopt: option requires an argument --$opt";
                            return PEAR::raiseError($msg);
                        }
                        $opt_arg = $args[$argIdx];
                    }

                    if (Console_Getopt::_isShortOpt($opt_arg)
                        || Console_Getopt::_isLongOpt($opt_arg)) {
                        $msg = "Console_Getopt: option requires an argument --$opt";
                        return PEAR::raiseError($msg);
                    }
                }
            } else if ($opt_arg) {
                $msg = "Console_Getopt: option --$opt doesn't allow an argument";
                return PEAR::raiseError($msg);
            }

            $opts[] = array('--' . $opt, $opt_arg);
            return;
        }

        if ($skip_unknown === true) {
            return;
        }

        return PEAR::raiseError("Console_Getopt: unrecognized option --$opt");
    }
76069
public function read(array $opts) {
        $translatorevents = [];

        // Push question statements to $translatorevents['events'].
        foreach ($opts['attempt']->questions as $questionId => $questionAttempt) {
            $question = $this->expandQuestion(
                $opts['questions'][$questionAttempt->questionid],
                $opts['questions']
            );
            array_push(
                $translatorevents,
                $this->questionStatement(
                    parent::read($opts)[0],
                    $questionAttempt,
                    $question
                )
            );
        }

        return $translatorevents;
    }
727852
function _Options($opts)
	{
		if (!is_array($opts)) return array();
		$newopts = array();
		foreach($opts as $k => $v) {
			if (is_numeric($k)) $newopts[strtoupper($v)] = $v;
			else $newopts[strtoupper($k)] = $v;
		}
		return $newopts;
	}
612143
protected function getOptions(array  $options): array
    {
        $options['format'] = array_get($options, 'format', $this->format);
        $options['locale'] = array_get($options, 'locale', config('app.locale'));

        return $options;
    }
70758
protected function getOptions(array  $options) : array
    {
        $options['format'] = Arr::get($options, 'format', $this->format);
        $options['locale'] = Arr::get($options, 'locale', config('app.locale'));

        return $options;
    }
653172
public function read(array $opts) {
        $scoreMax = $opts['scorm_scoes_track']['scoremax'];
        $scoreRaw = $opts['cmi_data']['cmivalue'];
        $scoreMin = $opts['scorm_scoes_track']['scoremin'];
        $scoreScaled = NULL;

        $scoreScaled = $scoreRaw >= 0 ? ($scoreRaw / $scoreMax) : ($scoreRaw / $scoreMin);

        return [array_merge(parent::read($opts)[0], [
            'recipe' => 'scorm_scoreraw_submitted',
            'scorm_score_raw' => $scoreRaw,
            'scorm_score_min' => $scoreMin,
            'scorm_score_max' => $scoreMax,
            'scorm_score_scaled' => $scoreScaled,
        ])];
    }
1325740
protected function loadCliOptions(array $opts)
    {
        $map = [
            'c' => 'conf_file',   // config file
            's' => 'servers', // server address

            'n' => 'workerNum',  // worker number do all tasks
            'u' => 'user',
            'g' => 'group',

            'l' => 'logFile',
            'p' => 'pidFile',

            'r' => 'maxRunTasks', // max run tasks for a worker
            'x' => 'maxLifetime',// max lifetime for a worker
            't' => 'timeout',
        ];

        // show help
        if (isset($opts['h']) || isset($opts['help'])) {
            $this->showHelp();
        }
        // show version
        if (isset($opts['V']) || isset($opts['version'])) {
            $this->showVersion();
        }

        // load opts values to config
        foreach ($map as $k => $v) {
            if (isset($opts[$k]) && $opts[$k]) {
                $this->config[$v] = $opts[$k];
            }
        }

        // load Custom Config File
        if ($file = $this->config['conf_file']) {
            if (!file_exists($file)) {
                $this->showHelp("Custom config file {$file} not found.");
            }

            $config = require $file;
            $this->setConfig($config);
        }

        // watch modify
        if (isset($opts['w']) || isset($opts['watch'])) {
            $this->config['watch_modify'] = $opts['w'];
        }

        // run as daemon
        if (isset($opts['d']) || isset($opts['daemon'])) {
            $this->config['daemon'] = true;
        }

        // no test
        if (isset($opts['no-test'])) {
            $this->config['no_test'] = true;
        }

        // only added tasks
        if (isset($opts['tasks']) && ($added = trim($opts['tasks'], ','))) {
            $this->config['added_tasks'] = strpos($added, ',') ? explode(',', $added) : [$added];
        }

        if (isset($opts['v'])) {
            $opts['v'] = $opts['v'] === true ? '' : $opts['v'];

            switch ($opts['v']) {
                case '':
                    $this->config['logLevel'] = self::LOG_INFO;
                    break;
                case 'v':
                    $this->config['logLevel'] = self::LOG_PROC_INFO;
                    break;
                case 'vv':
                    $this->config['logLevel'] = self::LOG_WORKER_INFO;
                    break;
                case 'vvv':
                    $this->config['logLevel'] = self::LOG_DEBUG;
                    break;
                case 'vvvv':
                    $this->config['logLevel'] = self::LOG_CRAZY;
                    break;
                default:
                    // $this->config['logLevel'] = self::LOG_INFO;
                    break;
            }
        }
    }
984442
protected function _options(array $opts)
    {
        if (!empty($opts['targetForeignKey'])) {
            $this->setTargetForeignKey($opts['targetForeignKey']);
        }
        if (!empty($opts['joinTable'])) {
            $this->_junctionTableName($opts['joinTable']);
        }
        if (!empty($opts['through'])) {
            $this->setThrough($opts['through']);
        }
        if (!empty($opts['saveStrategy'])) {
            $this->setSaveStrategy($opts['saveStrategy']);
        }
        if (isset($opts['sort'])) {
            $this->setSort($opts['sort']);
        }
    }
958259
function parseOptions(opts) {
  opts = opts || {};
  var argv = [];
  var options = {};
  var process_argv = process.argv;
  for (var i = 2; i < process_argv.length; i++) {
    if (process_argv[i].indexOf('--') == 0) {
      var arg = process_argv[i];
      if (arg.indexOf("=") > 0) {
        var arg_kv = arg.split('=');
        arg = arg_kv[0];
        arg = arg.replace('--','');
        arg = replaceAll(arg, '-', '_');
        options[arg] = arg_kv[1];
        if (typeof opts[arg] == 'string') {
          if (opts[arg] == 'int' || opts[arg] == 'integer') {
            options[arg] = parseInt(options[arg]);
          } else if (opts[arg] == 'float') {
            options[arg] = parseFloat(options[arg]);
          }
        } else if (typeof opts[arg] == 'object') {
          if (opts[arg].type == 'array') {
            var sep = opts[arg].separator || opts[arg].sep || ',';
            options[arg] = options[arg].split(sep);
          }
        }
      } else {
        arg = arg.replace('--','');
        arg = replaceAll(arg, '-', '_');
        options[arg] = true;
      }
    } else {
      argv.push(process_argv[i]);
    }
  }
  options.argv = argv;
  return options;
}
1266550
protected function parseOptions(array $options): array
    {
        $this->setTransformer(new IntegerToLocalizedStringTransformer($this->getLocale(), $this));

        return parent::parseOptions($options);
    }
1123359
protected function mergeOptions(array $options)
    {
        $merged = [];
        foreach ($this->supportedOptions() as $option) {
            $merged[$option] = $this->mergeOption($option, $options);
        }

        return $merged;
    }