Skip to content

Conversation

@gharlan
Copy link
Contributor

@gharlan gharlan commented Jun 30, 2025

  • Bug fix #…?
  • New feature?
  • BC breaks?
  • Tests added?
  • Docs added?

When using these options, a value is required.

->setName('init')
->setDescription('Initialize deployer in your project')
->addOption('path', 'p', InputOption::VALUE_OPTIONAL, 'Recipe path');
->addOption('path', 'p', InputOption::VALUE_REQUIRED, 'Recipe path');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, this is optional!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Options are always optional. But when using this option, a value is required.
Valid is init or init --path=/foo/bar.
But init --path without the value is invalid. So the value is not optional for this option.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a common mistake. Even in symfony itself I found some wrong usages of VALUE_OPTIONAL: symfony/symfony#60914

{
parent::configure();
$this->addOption('format', null, InputOption::VALUE_OPTIONAL, 'The output format (json, yaml)', 'yaml');
$this->addOption('format', null, InputOption::VALUE_REQUIRED, 'The output format (json, yaml)', 'yaml');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is optional and yaml by default.

@antonmedv antonmedv merged commit 30742fc into deployphp:master Jul 1, 2025
3 of 6 checks passed
@gharlan gharlan deleted the command-option-mode branch July 1, 2025 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants