Skip to content

Commit 41956b8

Browse files
alamiraultfabpot
authored andcommitted
Harmonize command formats and ensure autocompletion is same
1 parent b370bd3 commit 41956b8

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

Command/DebugCommand.php

Lines 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
}

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
}

0 commit comments

Comments
 (0)