8000 Make "files" argument optional (#14) · symfony-tools/code-block-checker@973a8ac · GitHub
[go: up one dir, main page]

Skip to content

Commit 973a8ac

Browse files
authored
Make "files" argument optional (#14)
1 parent 9f2643a commit 973a8ac

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"symfony/docs-builder": "^0.15.0",
1212
"symfony/dotenv": "^5.2",
1313
"symfony/event-dispatcher": "^5.2",
14+
"symfony/finder": "^5.2",
1415
"symfony/flex": "^1.3.1",
1516
"symfony/framework-bundle": "^5.2",
1617
"symfony/process": "^5.2",

src/Command/CheckDocsCommand.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Symfony\Component\Console\Output\OutputInterface;
2121
use Symfony\Component\Console\Style\SymfonyStyle;
2222
use Symfony\Component\Filesystem\Filesystem;
23+
use Symfony\Component\Finder\Finder;
2324
use SymfonyDocsBuilder\BuildConfig;
2425

2526
class CheckDocsCommand extends Command
@@ -43,7 +44,7 @@ protected function configure()
4344
{
4445
$this
4546
->addArgument('source-dir', InputArgument::REQUIRED, 'RST files Source directory')
46-
->addArgument('files', InputArgument::IS_ARRAY + InputArgument::REQUIRED, 'RST files that should be verified.')
47+
->addArgument('files', InputArgument::IS_ARRAY, 'RST files that should be verified.', [])
4748
->addOption('output-format', null, InputOption::VALUE_REQUIRED, 'Valid options are github and console', 'github')
4849
->addOption('generate-baseline', null, InputOption::VALUE_REQUIRED, 'Generate a new baseline', false)
4950
->addOption('baseline', null, InputOption::VALUE_REQUIRED, 'Use a baseline', false)
@@ -77,6 +78,10 @@ protected function initialize(InputInterface $input, OutputInterface $output)
7778
protected function execute(InputInterface $input, OutputInterface $output): int
7879
{
7980
$files = $input->getArgument('files');
81+
if ([] === $files) {
82+
$files = $this->findFiles($input->getArgument('source-dir'));
83+
}
84+
8085
$parseQueue = new ParseQueue();
8186
foreach ($files as $filename) {
8287
// Remove ".rst"
@@ -121,4 +126,17 @@ protected function execute(InputInterface $input, OutputInterface $output): int
121126

122127
return Command::SUCCESS;
123128
}
129+
130+
private function findFiles(string $directory): array
131+
{
132+
$files = [];
133+
$finder = new Finder();
134+
$finder->in($directory)
135+
->name('*.rst');
136+
foreach ($finder as $file) {
137+
$files[] = $file->getRelativePathname();
138+
}
139+
140+
return $files;
141+
}
124142
}

0 commit comments

Comments
 (0)
0