Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Console] Fix command option mode (InputOption::VALUE_REQUIRED) #60914

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 27, 2025

Conversation

gharlan
Copy link
Contributor

@gharlan gharlan commented Jun 26, 2025

Q A
Branch? 6.4
Bug fix? yes
New feature? no
Deprecations? no
Issues
License MIT

I think in all given cases it was a mistake to use InputOption::VALUE_OPTIONAL instead of InputOption::VALUE_REQUIRED.
It is a common mistake to think that you have to use VALUE_OPTIONAL to make the option optional. But options are always optional. 😉

@gharlan gharlan force-pushed the command-options-value-required branch from 34d24df to dde6dfa Compare June 26, 2025 21:24
Copy link
Member

@yceruto yceruto left a comment

Choose a reason for hiding this comment

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

Absolutely!

@carsonbot carsonbot changed the title Fix command option mode (InputOption::VALUE_REQUIRED) [Console] Fix command option mode (InputOption::VALUE_REQUIRED) Jun 27, 2025
new InputOption('sort', null, InputOption::VALUE_OPTIONAL, 'Return list of messages sorted alphabetically (only works with --dump-messages)', 'asc'),
new InputOption('as-tree', null, InputOption::VALUE_OPTIONAL, 'Dump the messages as a tree-like structure: The given value defines the level where to switch to inline YAML'),
new InputOption('as-tree', null, InputOption::VALUE_REQUIRED, 'Dump the messages as a tree-like structure: The given value defines the level where to switch to inline YAML'),
Copy link
Member

Choose a reason for hiding this comment

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

This one is an on/off, no value is expected here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The description says The given value defines the level where to switch to inline YAML..

And the help text of the command contains this:

<info>php %command.full_name% --force --format=yaml --as-tree=3 en AcmeBundle</info>

new InputOption('domains', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Specify the domains to pull.'),
new InputOption('locales', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Specify the locales to pull.'),
new InputOption('format', null, InputOption::VALUE_REQUIRED, 'Override the default output format.', 'xlf12'),
new InputOption('as-tree', null, InputOption::VALUE_REQUIRED, 'Write messages as a tree-like structure. Needs --format=yaml. The given value defines the level where to switch to inline YAML'),
Copy link
Member

Choose a reason for hiding this comment

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

Boolean option too, no value expected.

@nicolas-grekas
Copy link
Member

Thank you @gharlan.

@nicolas-grekas nicolas-grekas merged commit ff6d684 into symfony:6.4 Jun 27, 2025
10 of 11 checks passed
@gharlan gharlan deleted the command-options-value-required branch June 27, 2025 15:22
This was referenced Jun 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants