8000 minor #49929 Harmonize command formats and ensure autocompletion is s… · symfony/symfony@1250a93 · GitHub 10000
[go: up one dir, main page]

Skip to content

Commit 1250a93

Browse files
committed
minor #49929 Harmonize command formats and ensure autocompletion is same (alamirault)
This PR was squashed before being merged into the 6.3 branch. Discussion ---------- Harmonize command formats and ensure autocompletion is same | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | no | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | Fix #... <!-- prefix each issue number with "Fix #", no need to create an issue if none exists, explain below instead --> | License | MIT | Doc PR | symfony/symfony-docs#... <!-- required for new features --> This PR harmonize commands format option description and use sames values than autocompletion. Commits ------- b779b00 Harmonize command formats and ensure autocompletion is same
2 parents aaff87a + b779b00 commit 1250a93

File tree

12 files changed

+84
-42
lines changed

12 files changed

+84
-42
lines changed

src/Symfony/Bridge/Twig/Command/DebugCommand.php

-3Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ protected function configure()
6868
->setDefinition([
6969
new InputArgument('name', InputArgument::OPTIONAL, 'The template name'),
7070
new InputOption('filter', null, InputOption::VALUE_REQUIRED, 'Show details for all entries matching this filter'),
71-
new InputOption('format', null, InputOption::VALUE_REQUIRED, 'The output format (text or json)', 'text'),
71+
new InputOption('format', null, InputOption::VALUE_REQUIRED, sprintf('The output format ("%s")', implode('", "', $this->getAvailableFormatOptions())), 'text'),
7272
])
7373
->setHelp(<<<'EOF'
7474
The <info>%command.name%</info> command outputs a list of twig functions,
@@ -107,7 +107,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
107107
match ($input->getOption('format')) {
108108
'text' => $name ? $this->displayPathsText($io, $name) : $this->displayGeneralText($io, $filter),
109109
'json' => $name ? $this->displayPathsJson($io, $name) : $this->displayGeneralJson($io, $filter),
110-
default => throw new InvalidArgumentException(sprintf('The format "%s" is not supported.', $input->getOption('format'))),
110+
default => throw new InvalidArgumentException(sprintf('Supported formats are "%s".', implode('", "', $this->getAvailableFormatOptions()))),
111111
};
112112

113113
return 0;
@@ -120,7 +120,7 @@ public function complete(CompletionInput $input, CompletionSuggestions $suggesti
120120
}
121121

122122
if ($input->mustSuggestOptionValuesFor('format')) {
123-
$suggestions->suggestValues(['text', 'json']);
123+
$suggestions->suggestValues($this->getAvailableFormatOptions());
124124
}
125125
}
126126

@@ -596,4 +596,9 @@ private function getFileLink(string $absolutePath): string
596596

597597
return (string) $this->fileLinkFormatter->format($absolutePath, 1);
598598
}
599+
600+
private function getAvailableFormatOptions(): array
601+
{
602+
return ['text', 'json'];
603+
}
599604
}

src/Symfony/Bridge/Twig/Command/LintCommand.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function __construct(
5454
protected function configure()
5555
{
5656
$this
57-
->addOption('format', null, InputOption::VALUE_REQUIRED, 'The output format')
57+
->addOption('format', null, InputOption::VALUE_REQUIRED, sprintf('The output format ("%s")', implode('", "', $this->getAvailableFormatOptions())))
5858
->addOption('show-deprecations', null, InputOption::VALUE_NONE, 'Show deprecations as errors')
5959
->addArgument('filename', InputArgument::IS_ARRAY, 'A file, a directory or "-" for reading from STDIN')
6060
->setHelp(<<<'EOF'
@@ -178,7 +178,7 @@ private function display(InputInterface $input, OutputInterface $output, Symfony
178178
'txt' => $this->displayTxt($output, $io, $files),
179179
'json' => $this->displayJson($output, $files),
180180
'github' => $this->displayTxt($output, $io, $files, true),
181-
default => throw new InvalidArgumentException(sprintf('The format "%s" is not supported.', $input->getOption('format'))),
181+
default => throw new InvalidArgumentException(sprintf('Supported formats are "%s".', implode('", "', $this->getAvailableFormatOptions()))),
182182
};
183183
}
184184

@@ -276,7 +276,12 @@ private function getContext(string $template, int $line, int $context = 3): arra
276276
public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void
277277
{
278278
if ($input->mustSuggestOptionValuesFor('format')) {
279-
$suggestions->suggestValues(['txt', 'json', 'github']);
279+
$suggestions->suggestValues($this->getAvailableFormatOptions());
280280
}
281281
}
282+
283+
private function getAvailableFormatOptions(): array
284+
{
285+
return ['txt', 'json', 'github'];
286+
}
282287
}

src/Symfony/Bundle/FrameworkBundle/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

src/Symfony/Bundle/FrameworkBundle/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));

src/Symfony/Bundle/FrameworkBundle/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-
2CEB $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
}

src/Symfony/Bundle/FrameworkBundle/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
}

src/Symfony/Bundle/FrameworkBundle/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
}

src/Symfony/Component/Form/Command/DebugCommand.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ protected function configure()
6464
new InputArgument('class', InputArgument::OPTIONAL, 'The form type class'),
6565
new InputArgument('option', InputArgument::OPTIONAL, 'The form type option'),
6666
new InputOption('show-deprecated', null, InputOption::VALUE_NONE, 'Display deprecated options in form types'),
67-
new InputOption('format', null, InputOption::VALUE_REQUIRED, 'The output format (txt or json)', 'txt'),
67+
new InputOption('format', null, InputOption::VALUE_REQUIRED, sprintf('The output format ("%s")', implode('", "', $this->getAvailableFormatOptions())), 'txt'),
6868
])
6969
->setHelp(<<<'EOF'
7070
The <info>%command.name%</info> command displays information about form types.
@@ -261,8 +261,7 @@ public function complete(CompletionInput $input, CompletionSuggestions $suggesti
261261
}
262262

263263
if ($input->mustSuggestOptionValuesFor('format')) {
264-
$helper = new DescriptorHelper();
265-
$suggestions->suggestValues($helper->getFormats());
264+
$suggestions->suggestValues($this->getAvailableFormatOptions());
266265
}
267266
}
268267

@@ -283,4 +282,9 @@ private function completeOptions(string $class, CompletionSuggestions $suggestio
283282
$resolvedType = $this->formRegistry->getType($class);
284283
$suggestions->suggestValues($resolvedType->getOptionsResolver()->getDefinedOptions());
285284
}
285+
286+
private function getAvailableFormatOptions(): array
287+
{
288+
return (new DescriptorHelper())->getFormats();
289+
}
286290
}

src/Symfony/Component/Translation/Command/XliffLintCommand.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ protected function configure()
5757
{
5858
$this
5959
->addArgument('filename', InputArgument::IS_ARRAY, 'A file, a directory or "-" for reading from STDIN')
60-
->addOption('format', null, InputOption::VALUE_REQUIRED, 'The output format')
60+
->addOption('format', null, InputOption::VALUE_REQUIRED, sprintf('The output format ("%s")', implode('", "', $this->getAvailableFormatOptions())))
6161
->setHelp(<<<EOF
6262
The <info>%command.name%</info> command lints an XLIFF file and outputs to STDOUT
6363
the first encountered syntax error.
@@ -160,7 +160,7 @@ private function display(SymfonyStyle $io, array $files)
160160
'txt' => $this->displayTxt($io, $files),
161161
'json' => $this->displayJson($io, $files),
162162
'github' => $this->displayTxt($io, $files, true),
163-
default => throw new InvalidArgumentException(sprintf('The format "%s" is not supported.', $this->format)),
163+
default => throw new InvalidArgumentException(sprintf('Supported formats are "%s".', implode('", "', $this->getAvailableFormatOptions()))),
164164
};
165165
}
166166

@@ -268,7 +268,12 @@ private function getTargetLanguageFromFile(\DOMDocument $xliffContents): ?string
268268
public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void
269269
{
270270
if ($input->mustSuggestOptionValuesFor('format')) {
271-
$suggestions->suggestValues(['txt', 'json', 'github']);
271+
$suggestions->suggestValues($this->getAvailableFormatOptions());
272272
}
273273
}
274+
275+
private function getAvailableFormatOptions(): array
276+
{
277+
return ['txt', 'json', 'github'];
278+
}
274279
}

src/Symfony/Component/Uid/Command/GenerateUlidCommand.php

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,6 @@
2525
#[AsCommand(name: 'ulid:generate', description: 'Generate a ULID')]
2626
class GenerateUlidCommand extends Command
2727
{
28-
private const FORMAT_OPTIONS = [
29-
'base32',
30-
'base58',
31-
'rfc4122',
32-
];
33-
3428
private UlidFactory $factory;
3529

3630
public function __construct(UlidFactory $factory = null)
@@ -46,7 +40,7 @@ protected function configure(): void
4640
->setDefinition([
4741
new InputOption('time', null, InputOption::VALUE_REQUIRED, 'The ULID timestamp: a parsable date/time string'),
4842
new InputOption('count', 'c', InputOption::VALUE_REQUIRED, 'The number of ULID to generate', 1),
49-
new InputOption('format', 'f', InputOption::VALUE_REQUIRED, 'The ULID output format: base32, base58 or rfc4122', 'base32'),
43+
new InputOption('format', 'f', InputOption::VALUE_REQUIRED, sprintf('The ULID output format ("%s")', implode('", "', $this->getAvailableFormatOptions())), 'base32'),
5044
])
5145
->setHelp(<<<'EOF'
5246
The <info>%command.name%</info> command generates a ULID.
@@ -85,10 +79,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8579

8680
$formatOption = $input->getOption('format');
8781

88-
if (\in_array($formatOption, self::FORMAT_OPTIONS)) {
82+
if (\in_array($formatOption, $this->getAvailableFormatOptions())) {
8983
$format = 'to'.ucfirst($formatOption);
9084
} else {
91-
$io->error(sprintf('Invalid format "%s", did you mean "base32", "base58" or "rfc4122"?', $input->getOption('format')));
85+
$io->error(sprintf('Invalid format "%s", supported formats are "%s".', $formatOption, implode('", "', $this->getAvailableFormatOptions())));
9286

9387
return 1;
9488
}
@@ -110,7 +104,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int
110104
public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void
111105
{
112106
if ($input->mustSuggestOptionValuesFor('format')) {
113-
$suggestions->suggestValues(self::FORMAT_OPTIONS);
107+
$suggestions->suggestValues($this->getAvailableFormatOptions());
114108
}
115109
}
110+
111+
private function getAvailableFormatOptions(): array
112+
{
113+
return [
114+
'base32',
115+
'base58',
116+
'rfc4122',
117+
];
118+
}
116119
}

0 commit comments

Comments
 (0)
0