-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Add support for Hidden Options in Console #54206
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
Comments
Good idea 👍 If the goal is to handle deprecation in input options/arguments, we can add a
WDYT ? |
Sounds useful. If no one is working on it right now, I'll create a PR for that if it's okay. :) I've been working with Symfony for qa couple of time but this would be my first time contributing back ^^ Any support is welcome I want to help more in the feature :) |
Given deprecating input options is the main use case, why not |
Instead of adding a other argument, what about using flags instead? It's done for that |
It was my first thought but how can we set the deprecation message? It could be useful to give an alternative. |
Maybe an |
I see it as a trade-off. With "deprecations", we are giving an opinionated use for the "hide option" feature, which gives the developers a clear and well-integrated path for deprecations. With "hide option", we are giving a tool that developers can use as they see fit. I personally prefer "hide option" for two reasons:
Although admittedly, we lose some of the opinionated advantages such as What about both? class SendCommand extends Command
{
protected function configure()
{
$this
->setName('app:send')
->addOption( 'notify-hidden', null, InputOption::VALUE_NONE | InputOption::HIDDEN, 'Send a notification upon completion.', false )
->addOption( 'notify-deprecated', null, InputOption::VALUE_NONE | InputOption::DEPRECATED, '[Deprecated since 1.2.3. Will be removed in 2.0] Send a notification upon completion.', false )
}
} If using If using
If running PS: I haven't considered deeply if this applies for Arguments as well, I'll leave it to you Symfony People 😄. |
I'm building a CLI application using Console and I had two more instances where I wished I had hidden options.
I'm building a CLI tool that runs tests and spins up custom environments, eg:
Under the hood, this will call
Some of the parameters of
I pluralize it because these options are arrays, and they match what I read from config files (with Serializer, btw), eg: qit-env.yml
Pluralization makes sense on config context, but not on options (array) context, as a user might intuitively use If I had hidden options, I could programmatically create pluralized/non-pluralized options (where non-pluralized would be hidden). |
I am currently working on an implementation based on @Luc45 s idea.
The implementation is finished, I just have to adapt and extend the phpunit tests. |
Uh oh!
There was an error while loading. Please reload this page.
Description
Sometimes, we want to deprecate an option but not remove it immediately as to not break CI integration.
It would be ideal to be able to add a "hidden" option that doesn't show up on
--help
, but still works if you use it.Example
Suppose we have a command
app:send
with an existing option--notify
. We plan to deprecate--notify
but want to maintain it for backward compatibility. The hidden feature could be implemented as follows:Modifying the
addOption
Method:Add an additional argument to the
addOption
method in Symfony Console. This argument,isHidden
, is a boolean indicating whether the option should be hidden from the--help
output.Here's an example of defining the
--notify
option as a hidden option:Behavior with the --help Option:
When a user runs
app:send --help
, the output will not include the--notify
option, as it's marked hidden. However, the option will still function if used explicitly withapp:send --notify
.Use case: Deprecating options
The developer can use the option and warn the user about it's deprecation, without breaking backwards compatibility immediately. This is just one example use case.
The text was updated successfully, but these errors were encountered: