Skip to content

Commit f4d4715

Browse files
committed
feature #57518 Unify how --format is handled by commands (fabpot)
This PR was merged into the 7.2 branch. Discussion ---------- Unify how --format is handled by commands | Q | A | ------------- | --- | Branch? | 7.2 | Bug fix? | no | New feature? | yes <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | yes <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Issues | n/a <!-- prefix each issue number with "Fix #", no need to create an issue if none exists, explain below instead --> | License | MIT We have many commands that have a `--format` option. This PR tries to unify the way we handle them: * Deprecate the `text` format (used only twice) in favor of the more common `txt` one; * Add auto-completion for `--format` in all commands; * Add help about the `--format` option in all commands that supports it (in a unified way) **Side note**: To avoid confusion, I think we should rename the `--format` option for the `uuid:generate` and `ulid:generate` commands as it does something different from the commonly used `--format` option. Commits ------- 848f855cdf Unify how --format is handle by commands
2 parents 7159ac4 + 900b8ad commit f4d4715

File tree

5 files changed

+18
-11
lines changed

5 files changed

+18
-11
lines changed

Command/ConfigDebugCommand.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@ class ConfigDebugCommand extends AbstractConfigCommand
4141
{
4242
protected function configure(): void
4343
{
44-
$commentedHelpFormats = array_map(fn ($format) => \sprintf('<comment>%s</comment>', $format), $this->getAvailableFormatOptions());
45-
$helpFormats = implode('", "', $commentedHelpFormats);
46-
4744
$this
4845
->setDefinition([
4946
new InputArgument('name', InputArgument::OPTIONAL, 'The bundle name or the extension alias'),
@@ -60,8 +57,7 @@ protected function configure(): void
6057
<info>php %command.full_name% framework</info>
6158
<info>php %command.full_name% FrameworkBundle</info>
6259
63-
The <info>--format</info> option specifies the format of the configuration,
64-
these are "{$helpFormats}".
60+
The <info>--format</info> option specifies the format of the command output:
6561
6662
<info>php %command.full_name% framework --format=json</info>
6763
@@ -268,6 +264,7 @@ private static function buildPathsCompletion(array $paths, string $prefix = ''):
268264
return $completionPaths;
269265
}
270266

267+
/** @return string[] */
271268
private function getAvailableFormatOptions(): array
272269
{
273270
return ['txt', 'yaml', 'json'];

Command/ConfigDumpReferenceCommand.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@ class ConfigDumpReferenceCommand extends AbstractConfigCommand
3939
{
4040
protected function configure(): void
4141
{
42-
$commentedHelpFormats = array_map(fn ($format) => \sprintf('<comment>%s</comment>', $format), $this->getAvailableFormatOptions());
43-
$helpFormats = implode('", "', $commentedHelpFormats);
44-
4542
$this
4643
->setDefinition([
4744
new InputArgument('name', InputArgument::OPTIONAL, 'The Bundle name or the extension alias'),
@@ -57,10 +54,9 @@ protected function configure(): void
5754
<info>php %command.full_name% framework</info>
5855
<info>php %command.full_name% FrameworkBundle</info>
5956
60-
The <info>--format</info> option specifies the format of the configuration,
61-
these are "{$helpFormats}".
57+
The <info>--format</info> option specifies the format of the command output:
6258
63-
<info>php %command.full_name% FrameworkBundle --format=xml</info>
59+
<info>php %command.full_name% FrameworkBundle --format=json</info>
6460
6561
For dumping a specific option, add its path as second argument (only available for the yaml format):
6662
@@ -181,6 +177,7 @@ private function getAvailableBundles(): array
181177
return $bundles;
182178
}
183179

180+
/** @return string[] */
184181
private function getAvailableFormatOptions(): array
185182
{
186183
return ['yaml', 'xml'];

Command/ContainerDebugCommand.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ protected function configure(): void
106106
107107
<info>php %command.full_name% --show-hidden</info>
108108
109+
The <info>--format</info> option specifies the format of the command output:
110+
111+
<info>php %command.full_name% --format=json</info>
109112
EOF
110113
)
111114
;
@@ -358,6 +361,7 @@ public function filterToServiceTypes(string $serviceId): bool
358361
return class_exists($serviceId) || interface_exists($serviceId, false);
359362
}
360363

364+
/** @return string[] */
361365
private function getAvailableFormatOptions(): array
362366
{
363367
return (new DescriptorHelper())->getFormats();

Command/EventDispatcherDebugCommand.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ protected function configure(): void
6060
To get specific listeners for an event, specify its name:
6161
6262
<info>php %command.full_name% kernel.request</info>
63+
64+
The <info>--format</info> option specifies the format of the command output:
65+
66+
<info>php %command.full_name% --format=json</info>
6367
EOF
6468
)
6569
;
@@ -153,6 +157,7 @@ private function searchForEvent(EventDispatcherInterface $dispatcher, string $ne
153157
return $output;
154158
}
155159

160+
/** @return string[] */
156161
private function getAvailableFormatOptions(): array
157162
{
158163
return (new DescriptorHelper())->getFormats();

Command/RouterDebugCommand.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ protected function configure(): void
6161
6262
<info>php %command.full_name%</info>
6363
64+
The <info>--format</info> option specifies the format of the command output:
65+
66+
<info>php %command.full_name% --format=json</info>
6467
EOF
6568
)
6669
;
@@ -164,6 +167,7 @@ private function findRouteContaining(string $name, RouteCollection $routes): Rou
164167
return $foundRoutes;
165168
}
166169

170+
/** @return string[] */
167171
private function getAvailableFormatOptions(): array
168172
{
169173
return (new DescriptorHelper())->getFormats();

0 commit comments

Comments
 (0)