Skip to content

Commit abb0f24

Browse files
alamiraultfabpot
authored andcommitted
Harmonize command formats and ensure autocompletion is same
1 parent e2bacb4 commit abb0f24

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

Command/LintCommand.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
->addOption('exclude', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Path(s) to exclude')
6262
->addOption('parse-tags', null, InputOption::VALUE_NEGATABLE, 'Parse custom tags', null)
6363
->setHelp(<<<EOF
@@ -154,7 +154,7 @@ private function display(SymfonyStyle $io, array $files): int
154154
'txt' => $this->displayTxt($io, $files),
155155
'json' => $this->displayJson($io, $files),
156156
'github' => $this->displayTxt($io, $files, true),
157-
default => throw new InvalidArgumentException(sprintf('The format "%s" is not supported.', $this->format)),
157+
default => throw new InvalidArgumentException(sprintf('Supported formats are "%s".', implode('", "', $this->getAvailableFormatOptions()))),
158158
};
159159
}
160160

@@ -265,7 +265,12 @@ private function isReadable(string $fileOrDirectory): bool
265265
public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void
266266
{
267267
if ($input->mustSuggestOptionValuesFor('format')) {
268-
$suggestions->suggestValues(['txt', 'json', 'github']);
268+
$suggestions->suggestValues($this->getAvailableFormatOptions());
269269
}
270270
}
271+
272+
private function getAvailableFormatOptions(): array
273+
{
274+
return ['txt', 'json', 'github'];
275+
}
271276
}

0 commit comments

Comments
 (0)