private function insertMissingCommandNames(ArgsFormatInputDefinition $inputDefinition, $lenient = false)
{
// Start with the default values of the arguments.
$inputArguments = $inputDefinition->getArguments();
$fixedValues = array();
$commandNames = $inputDefinition->getCommandNamesByArgumentName();
// Flatten the actual arguments, in case they contain a multi-valued
// argument.
$actualValues = $this->flatten($this->arguments);
// Reset all array pointers.
reset($commandNames);
reset($actualValues);
reset($inputArguments);
// Skip the command names. The resulting pointer is like this:
//
// actual: [ 0: remote, 1: origin, 2: foo/bar ]
// ^
$this->skipCommandNames($actualValues, $commandNames);
// Copy the command names into the fixed array. The result is:
//
// fixed: [ cmd1: remote, cmd2: add ]
$this->copyArgumentValues($commandNames, $inputArguments, $fixedValues, $lenient);
// Copy the remaining actual values. The result is:
//
// fixed: [ cmd1: remote, cmd2: add, name: origin, target: foo/bar ]
$this->copyArgumentValues($actualValues, $inputArguments, $fixedValues, $lenient);
// Overwrite all current arguments with the fixed values
foreach ($fixedValues as $name => $value) {
$this->arguments[$name] = $value;
}
}