/** * Merge options from $definition, $local_defaults and $passed * * Precedence: $passed > $local_defaults > $definition * * @param array() $local_defaults * @param array() $options * * @return \Symfony\Component\Console\Input\ArrayInput */ public function __construct($local_defaults, $passed = null) { # if $passed is null, get and parse argv passed by CLI if (empty($passed)) { $passed = $this->getOptionsFromRequest(); } # init array to construct ArrayInput $merged = []; $definition = new GinnyDefinition(); foreach ($definition->getOptions() as $name => $option) { $merged['--' . $name] = $option->getDefault(); // override if set in $local_defaults if (array_key_exists($name, $local_defaults)) { $merged['--' . $name] = $local_defaults[$name]; } // override with shortcut in $passed if ($option->getShortcut()) { if (array_key_exists('-' . $option->getShortcut(), $passed)) { $merged['--' . $name] = $passed['-' . $option->getShortcut()]; } } // likewise replace with fully-name option in $passed if (array_key_exists('--' . $name, $passed)) { $merged['--' . $name] = $passed['--' . $name]; } } parent::__construct($merged); }