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

[Console] Add of hidden and deprecation option flags#54439

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
flkasper wants to merge15 commits intosymfony:7.4
base:7.4
Choose a base branch
Loading
fromflkasper:feature/7.1-hidden-and-deprecated-options
Open
Show file tree
Hide file tree
Changes from1 commit
Commits
Show all changes
15 commits
Select commitHold shift + click to select a range
2cf5da9
[Console] Add of hidden and deprecation option flags
flkasperMar 25, 2024
d203a4e
Fix code style
flkasperMar 29, 2024
4d86a42
Change style of deprecated option to inline formatting
flkasperMar 31, 2024
69b4bf8
[Console] Change color of deprecated option to gray
flkasperApr 6, 2024
e2d3f12
[Console] Fixed test after color change
flkasperApr 6, 2024
ece8b7a
[Console] Revert unrelated (style) changes
flkasperApr 8, 2024
a08e4d5
[Console] Apply suggestion changes
flkasperApr 8, 2024
02f0e0e
[Console] Fixed name of method
flkasperApr 9, 2024
d4be218
[Console] Revert unrelated (style) changes
flkasperApr 11, 2024
54baa40
[Console] Applied change suggestion in Command::writeDeprecationMessages
flkasperApr 11, 2024
9a9ab17
[Console] Added suggested description prefix to deprecated options in…
flkasperApr 11, 2024
cda876f
[Console] Apply suggestion & fixed coding standard of changes
flkasperApr 14, 2024
c615abe
Apply suggestions from code review
flkasperAug 26, 2024
6602bb4
Cleanup after rebase
flkasperSep 7, 2024
05ad7d4
Apply cs patch
flkasperSep 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
[Console] Change color of deprecated option to gray
  • Loading branch information
@flkasper
flkasper committedSep 7, 2024
commit69b4bf8c5a6e1a28288d5bbfaffa5a35e96d9a99
6 changes: 4 additions & 2 deletionssrc/Symfony/Component/Console/Command/Command.php
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,6 +19,7 @@
use Symfony\Component\Console\Exception\ExceptionInterface;
use Symfony\Component\Console\Exception\InvalidArgumentException;
use Symfony\Component\Console\Exception\LogicException;
use Symfony\Component\Console\Helper\FormatterHelper;
use Symfony\Component\Console\Helper\HelperInterface;
use Symfony\Component\Console\Helper\HelperSet;
use Symfony\Component\Console\Input\InputArgument;
Expand DownExpand Up@@ -275,7 +276,7 @@ public function run(InputInterface $input, OutputInterface $output): int
$input->validate();

if (isset($inputDefinition)) {

Choose a reason for hiding this comment

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

why the isset?

Suggested change
if (isset($inputDefinition)) {
if ($inputDefinition) {

Copy link
Member

Choose a reason for hiding this comment

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

$inputDefinition is defined in a try..catch, but should be outside.

nicolas-grekas reacted with thumbs up emoji
Copy link
Author

@flkasperflkasperAug 26, 2024
edited
Loading

Choose a reason for hiding this comment

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

As@GromNaN has already explained,$inputDefinition is defined within a try...catch:

try {    $inputDefinition = $this->getDefinition();    $input->bind($inputDefinition);} catch (ExceptionInterface $e) {    if (!$this->ignoreValidationErrors) {        throw $e;    }}

SincegetDefinition can also throw an exception (if the parent constructor call is missing), moving it outside the try...catch makes little sense.

Therefore,isset must be used to check whether$inputDefinition is defined.

$this->printDeprecationMessages($inputDefinition, $input, $output);
$this->writeDeprecationMessages($inputDefinition, $input, $output);
}

if ($this->code) {
Expand DownExpand Up@@ -653,7 +654,7 @@ public function getHelper(string $name): HelperInterface
return $this->helperSet->get($name);
}

private functionprintDeprecationMessages(InputDefinition $inputDefinition, InputInterface $input, OutputInterface $output): void
private functionwriteDeprecationMessages(InputDefinition $inputDefinition, InputInterface $input, OutputInterface $output): void
{
$deprecationMessages = [];
foreach ($inputDefinition->getOptions() as $inputOption) {
Expand All@@ -670,6 +671,7 @@ private function printDeprecationMessages(InputDefinition $inputDefinition, Inpu
}
}
if (!empty($deprecationMessages)) {
/** @var FormatterHelper $formatter */
$formatter = $this->getHelper('formatter');
$output->writeln($formatter->formatBlock($deprecationMessages, 'fg=black;bg=yellow', true));
}
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -74,7 +74,7 @@ protected function describeInputOption(InputOption $option, array $options = [])
$spacingWidth = $totalWidth - Helper::width($synopsis);

$this->writeText(\sprintf(' %s %s%s%s%s',
\sprintf('<%1$s>%2$s</%1$s>', $option->isDeprecated() ? 'text_error' : 'info', $synopsis),
\sprintf('<%1$s>%2$s</%1$s>', $option->isDeprecated() ? 'fg=gray;' : 'info', $synopsis),
str_repeat(' ', $spacingWidth),
// + 4 = 2 spaces before <info>, 2 spaces after </info>
preg_replace('/\s*[\r\n]\s*/', "\n".str_repeat(' ', $totalWidth + 4), $option->getDescription()),
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp