Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add support for Hidden Options in Console #54206

Open
@Luc45

Description

@Luc45

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 commandapp: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 theaddOption Method:

Add an additional argument to theaddOption 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:

useSymfony\Component\Console\Command\Command;useSymfony\Component\Console\Input\InputOption;class SendCommandextends Command{protectedfunctionconfigure()    {$this            ->setName('app:send')// other options and configuration            ->addOption('notify',null,                InputOption::VALUE_NONE,'Send a notification upon completion.',false,true// New argument 'isHidden' set to true            );    }}

Behavior with the --help Option:

When a user runsapp: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.

protectedfunctionexecute(InputInterface$input,OutputInterface$output){if ($input->getOption('notify')) {$output->writeln('<comment>Warning: The --notify option is deprecated and will be removed in a future version.</comment>');// Execute notify functionality    }// Rest of the command execution}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp