Skip to content

Commit 19c9fa1

Browse files
alamiraultfabpot
authored andcommitted
Harmonize command formats and ensure autocompletion is same
1 parent 8bad212 commit 19c9fa1

File tree

5 files changed

+30
-15
lines changed

5 files changed

+30
-15
lines changed

Command/ConfigDebugCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ protected function configure(): void
6161
<info>php %command.full_name% FrameworkBundle</info>
6262
6363
The <info>--format</info> option specifies the format of the configuration,
64-
this is either "{$helpFormats}".
64+
these are "{$helpFormats}".
6565
6666
<info>php %command.full_name% framework --format=json</info>
6767

Command/ConfigDumpReferenceCommand.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,16 @@ class ConfigDumpReferenceCommand extends AbstractConfigCommand
4141
{
4242
protected function configure(): void
4343
{
44+
$commentedHelpFormats = array_map(static fn (string $format): string => sprintf('<comment>%s</comment>', $format), $this->getAvailableFormatOptions());
45+
$helpFormats = implode('", "', $commentedHelpFormats);
46+
4447
$this
4548
->setDefinition([
4649
new InputArgument('name', InputArgument::OPTIONAL, 'The Bundle name or the extension alias'),
4750
new InputArgument('path', InputArgument::OPTIONAL, 'The configuration option path'),
48-
new InputOption('format', null, InputOption::VALUE_REQUIRED, 'The output format (yaml or xml)', 'yaml'),
51+
new InputOption('format', null, InputOption::VALUE_REQUIRED, sprintf('The output format ("%s")', implode('", "', $this->getAvailableFormatOptions())), 'yaml'),
4952
])
50-
->setHelp(<<<'EOF'
53+
->setHelp(<<<EOF
5154
The <info>%command.name%</info> command dumps the default configuration for an
5255
extension/bundle.
5356
@@ -56,9 +59,8 @@ protected function configure(): void
5659
<info>php %command.full_name% framework</info>
5760
<info>php %command.full_name% FrameworkBundle</info>
5861
59-
With the <info>--format</info> option specifies the format of the configuration,
60-
this is either <comment>yaml</comment> or <comment>xml</comment>.
61-
When the option is not provided, <comment>yaml</comment> is used.
62+
The <info>--format</info> option specifies the format of the configuration,
63+
these are "{$helpFormats}".
6264
6365
<info>php %command.full_name% FrameworkBundle --format=xml</info>
6466
@@ -145,7 +147,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
145147
break;
146148
default:
147149
$io->writeln($message);
148-
throw new InvalidArgumentException('Only the yaml and xml formats are supported.');
150+
throw new InvalidArgumentException(sprintf('Supported formats are "%s".', implode('", "', $this->getAvailableFormatOptions())));
149151
}
150152

151153
$io->writeln(null === $path ? $dumper->dump($configuration, $extension->getNamespace()) : $dumper->dumpAtPath($configuration, $path));

Command/ContainerDebugCommand.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ protected function configure(): void
5252
new InputOption('types', null, InputOption::VALUE_NONE, 'Display types (classes/interfaces) available in the container'),
5353
new InputOption('env-var', null, InputOption::VALUE_REQUIRED, 'Display a specific environment variable used in the container'),
5454
new InputOption('env-vars', null, InputOption::VALUE_NONE, 'Display environment variables used in the container'),
55-
new InputOption('format', null, InputOption::VALUE_REQUIRED, 'The output format (txt, xml, json, or md)', 'txt'),
55+
new InputOption('format', null, InputOption::VALUE_REQUIRED, sprintf('The output format ("%s")', implode('", "', $this->getAvailableFormatOptions())), 'txt'),
5656
new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw description'),
5757
new InputOption('deprecations', null, InputOption::VALUE_NONE, 'Display deprecations generated when compiling and warming up the container'),
5858
])
@@ -203,8 +203,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
203203
public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void
204204
{
205205
if ($input->mustSuggestOptionValuesFor('format')) {
206-
$helper = new DescriptorHelper();
207-
$suggestions->suggestValues($helper->getFormats());
206+
$suggestions->suggestValues($this->getAvailableFormatOptions());
208207

209208
return;
210209
}
@@ -352,4 +351,9 @@ public function filterToServiceTypes(string $serviceId): bool
352351

353352
return class_exists($serviceId) || interface_exists($serviceId, false);
354353
}
354+
355+
private function getAvailableFormatOptions(): array
356+
{
357+
return (new DescriptorHelper())->getFormats();
358+
}
355359
}

Command/EventDispatcherDebugCommand.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ protected function configure(): void
5252
->setDefinition([
5353
new InputArgument('event', InputArgument::OPTIONAL, 'An event name or a part of the event name'),
5454
new InputOption('dispatcher', null, InputOption::VALUE_REQUIRED, 'To view events of a specific event dispatcher', self::DEFAULT_DISPATCHER),
55-
new InputOption('format', null, InputOption::VALUE_REQUIRED, 'The output format (txt, xml, json, or md)', 'txt'),
55+
new InputOption('format', null, InputOption::VALUE_REQUIRED, sprintf('The output format ("%s")', implode('", "', $this->getAvailableFormatOptions())), 'txt'),
5656
new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw description'),
5757
])
5858
->setHelp(<<<'EOF'
@@ -138,7 +138,7 @@ public function complete(CompletionInput $input, CompletionSuggestions $suggesti
138138
}
139139

140140
if ($input->mustSuggestOptionValuesFor('format')) {
141-
$suggestions->suggestValues((new DescriptorHelper())->getFormats());
141+
$suggestions->suggestValues($this->getAvailableFormatOptions());
142142
}
143143
}
144144

@@ -155,4 +155,9 @@ private function searchForEvent(EventDispatcherInterface $dispatcher, string $ne
155155

156156
return $output;
157157
}
158+
159+
private function getAvailableFormatOptions(): array
160+
{
161+
return (new DescriptorHelper())->getFormats();
162+
}
158163
}

Command/RouterDebugCommand.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ protected function configure(): void
5656
->setDefinition([
5757
new InputArgument('name', InputArgument::OPTIONAL, 'A route name'),
5858
new InputOption('show-controllers', null, InputOption::VALUE_NONE, 'Show assigned controllers in overview'),
59-
new InputOption('format', null, InputOption::VALUE_REQUIRED, 'The output format (txt, xml, json, or md)', 'txt'),
59+
new InputOption('format', null, InputOption::VALUE_REQUIRED, sprintf('The output format ("%s")', implode('", "', $this->getAvailableFormatOptions())), 'txt'),
6060
new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw route(s)'),
6161
])
6262
->setHelp(<<<'EOF'
@@ -149,8 +149,7 @@ public function complete(CompletionInput $input, CompletionSuggestions $suggesti
149149
}
150150

151151
if ($input->mustSuggestOptionValuesFor('format')) {
152-
$helper = new DescriptorHelper();
153-
$suggestions->suggestValues($helper->getFormats());
152+
$suggestions->suggestValues($this->getAvailableFormatOptions());
154153
}
155154
}
156155

@@ -165,4 +164,9 @@ private function findRouteContaining(string $name, RouteCollection $routes): Rou
165164

166165
return $foundRoutes;
167166
}
167+
168+
private function getAvailableFormatOptions(): array
169+
{
170+
return (new DescriptorHelper())->getFormats();
171+
}
168172
}

0 commit comments

Comments
 (0)