private $hidden = false;
private $help = '';
private $description = '';
+ private $fullDefinition;
private $ignoreValidationErrors = false;
- private $applicationDefinitionMerged = false;
- private $applicationDefinitionMergedWithArgs = false;
private $code;
private $synopsis = [];
private $usages = [];
} else {
$this->helperSet = null;
}
+
+ $this->fullDefinition = null;
}
public function setHelperSet(HelperSet $helperSet)
*/
public function run(InputInterface $input, OutputInterface $output)
{
- // force the creation of the synopsis before the merge with the app definition
- $this->getSynopsis(true);
- $this->getSynopsis(false);
-
// add the application arguments and options
$this->mergeApplicationDefinition();
// bind the input against the command specific arguments/options
try {
- $input->bind($this->definition);
+ $input->bind($this->getDefinition());
} catch (ExceptionInterface $e) {
if (!$this->ignoreValidationErrors) {
throw $e;
if (null !== $this->processTitle) {
if (\function_exists('cli_set_process_title')) {
if (!@cli_set_process_title($this->processTitle)) {
- if ('Darwin' === PHP_OS) {
+ if ('Darwin' === \PHP_OS) {
$output->writeln('<comment>Running "cli_set_process_title" as an unprivileged user is not supported on MacOS.</comment>', OutputInterface::VERBOSITY_VERY_VERBOSE);
} else {
cli_set_process_title($this->processTitle);
*/
public function mergeApplicationDefinition(bool $mergeArgs = true)
{
- if (null === $this->application || (true === $this->applicationDefinitionMerged && ($this->applicationDefinitionMergedWithArgs || !$mergeArgs))) {
+ if (null === $this->application) {
return;
}
- $this->definition->addOptions($this->application->getDefinition()->getOptions());
-
- $this->applicationDefinitionMerged = true;
+ $this->fullDefinition = new InputDefinition();
+ $this->fullDefinition->setOptions($this->definition->getOptions());
+ $this->fullDefinition->addOptions($this->application->getDefinition()->getOptions());
if ($mergeArgs) {
- $currentArguments = $this->definition->getArguments();
- $this->definition->setArguments($this->application->getDefinition()->getArguments());
- $this->definition->addArguments($currentArguments);
-
- $this->applicationDefinitionMergedWithArgs = true;
+ $this->fullDefinition->setArguments($this->application->getDefinition()->getArguments());
+ $this->fullDefinition->addArguments($this->definition->getArguments());
+ } else {
+ $this->fullDefinition->setArguments($this->definition->getArguments());
}
}
$this->definition->setDefinition($definition);
}
- $this->applicationDefinitionMerged = false;
+ $this->fullDefinition = null;
return $this;
}
*/
public function getDefinition()
{
- if (null === $this->definition) {
- throw new LogicException(sprintf('Command class "%s" is not correctly initialized. You probably forgot to call the parent constructor.', static::class));
- }
-
- return $this->definition;
+ return $this->fullDefinition ?? $this->getNativeDefinition();
}
/**
*/
public function getNativeDefinition()
{
- return $this->getDefinition();
+ if (null === $this->definition) {
+ throw new LogicException(sprintf('Command class "%s" is not correctly initialized. You probably forgot to call the parent constructor.', static::class));
+ }
+
+ return $this->definition;
}
/**
public function addArgument(string $name, int $mode = null, string $description = '', $default = null)
{
$this->definition->addArgument(new InputArgument($name, $mode, $description, $default));
+ if (null !== $this->fullDefinition) {
+ $this->fullDefinition->addArgument(new InputArgument($name, $mode, $description, $default));
+ }
return $this;
}
public function addOption(string $name, $shortcut = null, int $mode = null, string $description = '', $default = null)
{
$this->definition->addOption(new InputOption($name, $shortcut, $mode, $description, $default));
+ if (null !== $this->fullDefinition) {
+ $this->fullDefinition->addOption(new InputOption($name, $shortcut, $mode, $description, $default));
+ }
return $this;
}