-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 7.4
Are you sure you want to change the base?
Changes from 1 commit
2cf5da9
d203a4e
4d86a42
69b4bf8
e2d3f12
ece8b7a
a08e4d5
02f0e0e
d4be218
54baa40
9a9ab17
cda876f
c615abe
6602bb4
05ad7d4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
; Unix-style newlines | ||
[Tests/Fixtures/*.{json,md,rst,txt}] | ||
trim_trailing_whitespace = false | ||
|
||
[Tests/Fixtures/*.xml] | ||
trim_trailing_whitespace = false | ||
indent_size = 2 |
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -235,7 +235,8 @@ public function run(InputInterface $input, OutputInterface $output): int | |||
|
||||
// bind the input against the command specific arguments/options | ||||
try { | ||||
$input->bind($this->getDefinition()); | ||||
$inputDefinition = $this->getDefinition(); | ||||
$input->bind($inputDefinition); | ||||
} catch (ExceptionInterface $e) { | ||||
if (!$this->ignoreValidationErrors) { | ||||
throw $e; | ||||
|
@@ -273,6 +274,10 @@ public function run(InputInterface $input, OutputInterface $output): int | |||
|
||||
$input->validate(); | ||||
|
||||
if (isset($inputDefinition)) { | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why the isset?
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As @GromNaN has already explained,
Since Therefore, |
||||
$this->printDeprecationMessages($inputDefinition, $input, $output); | ||||
} | ||||
|
||||
if ($this->code) { | ||||
$statusCode = ($this->code)($input, $output); | ||||
} else { | ||||
|
@@ -648,6 +653,28 @@ public function getHelper(string $name): HelperInterface | |||
return $this->helperSet->get($name); | ||||
} | ||||
|
||||
private function printDeprecationMessages(InputDefinition $inputDefinition, InputInterface $input, OutputInterface $output): void | ||||
{ | ||||
$deprecationMessages = []; | ||||
foreach ($inputDefinition->getOptions() as $inputOption) { | ||||
if ($inputOption->isDeprecated()) { | ||||
try { | ||||
$optionName = $inputOption->getName(); | ||||
$optionValue = $input->getOption($optionName); | ||||
if (isset($optionValue) && $optionValue !== $inputOption->getDefault()) { | ||||
flkasper marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
$deprecationMessages[] = sprintf('The option "--%s" is deprecated.', $optionName); | ||||
flkasper marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
} | ||||
} catch (\InvalidArgumentException $exception) { | ||||
// option not used, ignore | ||||
} | ||||
} | ||||
} | ||||
if (!empty($deprecationMessages)) { | ||||
flkasper marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
$formatter = $this->getHelper('formatter'); | ||||
$output->writeln($formatter->formatBlock($deprecationMessages, 'fg=black;bg=yellow', true)); | ||||
} | ||||
} | ||||
|
||||
/** | ||||
* Validates a command name. | ||||
* | ||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,9 @@ protected function describeInputArgument(InputArgument $argument, array $options | |
|
||
protected function describeInputOption(InputOption $option, array $options = []): void | ||
{ | ||
if ($this->skipHiddenOption($option, $options)) { | ||
return; | ||
} | ||
$this->writeData($this->getInputOptionData($option), $options); | ||
if ($option->isNegatable()) { | ||
$this->writeData($this->getInputOptionData($option, true), $options); | ||
|
@@ -41,12 +44,12 @@ protected function describeInputOption(InputOption $option, array $options = []) | |
|
||
protected function describeInputDefinition(InputDefinition $definition, array $options = []): void | ||
{ | ||
$this->writeData($this->getInputDefinitionData($definition), $options); | ||
$this->writeData($this->getInputDefinitionData($definition, $options), $options); | ||
} | ||
|
||
protected function describeCommand(Command $command, array $options = []): void | ||
{ | ||
$this->writeData($this->getCommandData($command, $options['short'] ?? false), $options); | ||
$this->writeData($this->getCommandData($command, $options), $options); | ||
} | ||
|
||
protected function describeApplication(Application $application, array $options = []): void | ||
|
@@ -56,7 +59,7 @@ protected function describeApplication(Application $application, array $options | |
$commands = []; | ||
|
||
foreach ($description->getCommands() as $command) { | ||
$commands[] = $this->getCommandData($command, $options['short'] ?? false); | ||
$commands[] = $this->getCommandData($command, $options); | ||
} | ||
|
||
$data = []; | ||
|
@@ -101,34 +104,40 @@ private function getInputArgumentData(InputArgument $argument): array | |
|
||
private function getInputOptionData(InputOption $option, bool $negated = false): array | ||
{ | ||
return $negated ? [ | ||
'name' => '--no-'.$option->getName(), | ||
$data = $negated ? [ | ||
'name' => '--no-' . $option->getName(), | ||
'shortcut' => '', | ||
'accept_value' => false, | ||
'is_value_required' => false, | ||
'is_multiple' => false, | ||
'description' => 'Negate the "--'.$option->getName().'" option', | ||
'is_deprecated' => $option->isDeprecated(), | ||
'description' => 'Negate the "--' . $option->getName() . '" option', | ||
'default' => false, | ||
] : [ | ||
'name' => '--'.$option->getName(), | ||
'shortcut' => $option->getShortcut() ? '-'.str_replace('|', '|-', $option->getShortcut()) : '', | ||
'name' => '--' . $option->getName(), | ||
'shortcut' => $option->getShortcut() ? '-' . str_replace('|', '|-', $option->getShortcut()) : '', | ||
'accept_value' => $option->acceptValue(), | ||
'is_value_required' => $option->isValueRequired(), | ||
'is_multiple' => $option->isArray(), | ||
'is_deprecated' => $option->isDeprecated(), | ||
'description' => preg_replace('/\s*[\r\n]\s*/', ' ', $option->getDescription()), | ||
'default' => \INF === $option->getDefault() ? 'INF' : $option->getDefault(), | ||
]; | ||
if (!$option->isDeprecated()) { | ||
unset($data['is_deprecated']); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would not unset this. The json is easier to use if we don't have conditional keys in it. |
||
} | ||
return $data; | ||
} | ||
|
||
private function getInputDefinitionData(InputDefinition $definition): array | ||
private function getInputDefinitionData(InputDefinition $definition, array $options): array | ||
{ | ||
$inputArguments = []; | ||
foreach ($definition->getArguments() as $name => $argument) { | ||
$inputArguments[$name] = $this->getInputArgumentData($argument); | ||
} | ||
|
||
$inputOptions = []; | ||
foreach ($definition->getOptions() as $name => $option) { | ||
foreach ($this->removeHiddenOptions($definition->getOptions(), $options) as $name => $option) { | ||
$inputOptions[$name] = $this->getInputOptionData($option); | ||
if ($option->isNegatable()) { | ||
$inputOptions['no-'.$name] = $this->getInputOptionData($option, true); | ||
|
@@ -138,8 +147,10 @@ private function getInputDefinitionData(InputDefinition $definition): array | |
return ['arguments' => $inputArguments, 'options' => $inputOptions]; | ||
} | ||
|
||
private function getCommandData(Command $command, bool $short = false): array | ||
private function getCommandData(Command $command, array $options = []): array | ||
{ | ||
$short = $options['short'] ?? false; | ||
|
||
$data = [ | ||
'name' => $command->getName(), | ||
'description' => $command->getDescription(), | ||
|
@@ -155,7 +166,7 @@ private function getCommandData(Command $command, bool $short = false): array | |
$data += [ | ||
'usage' => array_merge([$command->getSynopsis()], $command->getUsages(), $command->getAliases()), | ||
'help' => $command->getProcessedHelp(), | ||
'definition' => $this->getInputDefinitionData($command->getDefinition()), | ||
'definition' => $this->getInputDefinitionData($command->getDefinition(), $options), | ||
]; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,6 +70,7 @@ protected function describeInputOption(InputOption $option, array $options = []) | |
.'* Accept value: '.($option->acceptValue() ? 'yes' : 'no')."\n" | ||
.'* Is value required: '.($option->isValueRequired() ? 'yes' : 'no')."\n" | ||
.'* Is multiple: '.($option->isArray() ? 'yes' : 'no')."\n" | ||
.($option->isDeprecated() ? ('* Is deprecated: yes'."\n") : '') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't we have a line |
||
.'* Is negatable: '.($option->isNegatable() ? 'yes' : 'no')."\n" | ||
.'* Default: `'.str_replace("\n", '', var_export($option->getDefault(), true)).'`' | ||
); | ||
|
@@ -81,19 +82,20 @@ protected function describeInputDefinition(InputDefinition $definition, array $o | |
$this->write('### Arguments'); | ||
foreach ($definition->getArguments() as $argument) { | ||
$this->write("\n\n"); | ||
$this->describeInputArgument($argument); | ||
$this->describeInputArgument($argument, $options); | ||
} | ||
} | ||
|
||
if (\count($definition->getOptions()) > 0) { | ||
$inputOptions = $this->removeHiddenOptions($definition->getOptions(), $options); | ||
if (!empty($inputOptions)) { | ||
flkasper marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if ($showArguments) { | ||
$this->write("\n\n"); | ||
} | ||
|
||
$this->write('### Options'); | ||
foreach ($definition->getOptions() as $option) { | ||
foreach ($inputOptions as $option) { | ||
$this->write("\n\n"); | ||
$this->describeInputOption($option); | ||
$this->describeInputOption($option, $options); | ||
} | ||
} | ||
} | ||
|
@@ -128,9 +130,9 @@ protected function describeCommand(Command $command, array $options = []): void | |
} | ||
|
||
$definition = $command->getDefinition(); | ||
if ($definition->getOptions() || $definition->getArguments()) { | ||
if ($this->removeHiddenOptions($definition->getOptions(), $options) || $definition->getArguments()) { | ||
$this->write("\n\n"); | ||
$this->describeInputDefinition($definition); | ||
$this->describeInputDefinition($definition, $options); | ||
} | ||
} | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.