Skip to content

Commit a9281e7

Browse files
authored
Merge pull request #441 from greg0ire/progress-bar
Add progress bar to the run command
2 parents b164d63 + 4bb8714 commit a9281e7

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

packages/guides-cli/src/Command/Run.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@
2121
use phpDocumentor\Guides\Twig\Theme\ThemeManager;
2222
use RuntimeException;
2323
use Symfony\Component\Console\Command\Command;
24+
use Symfony\Component\Console\Helper\ProgressBar;
2425
use Symfony\Component\Console\Input\InputArgument;
2526
use Symfony\Component\Console\Input\InputInterface;
2627
use Symfony\Component\Console\Input\InputOption;
28+
use Symfony\Component\Console\Output\ConsoleOutputInterface;
2729
use Symfony\Component\Console\Output\OutputInterface;
2830

2931
use function array_pop;
@@ -89,6 +91,14 @@ public function __construct(
8991
'The theme used for rendering.',
9092
'default',
9193
);
94+
95+
$this->addOption(
96+
'progress',
97+
null,
98+
InputOption::VALUE_NEGATABLE,
99+
'Whether to show a progress bar',
100+
true,
101+
);
92102
}
93103

94104
protected function execute(InputInterface $input, OutputInterface $output): int
@@ -146,10 +156,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int
146156
$outputFormats = $input->getOption('output-format');
147157

148158
foreach ($outputFormats as $format) {
159+
$progressBar = null;
160+
161+
if ($output instanceof ConsoleOutputInterface && $input->getOption('progress')) {
162+
$progressBar = new ProgressBar($output->section());
163+
}
164+
149165
$this->commandBus->handle(
150166
new RenderCommand(
151167
$format,
152-
$documents,
168+
$progressBar === null ? $documents : $progressBar->iterate($documents),
153169
$sourceFileSystem,
154170
$destinationFileSystem,
155171
$projectNode,

packages/guides/src/Handlers/RenderCommand.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010

1111
final class RenderCommand
1212
{
13-
/** @param DocumentNode[] $documents */
13+
/** @param iterable<DocumentNode> $documents */
1414
public function __construct(
1515
private readonly string $outputFormat,
16-
private readonly array $documents,
16+
private readonly iterable $documents,
1717
private readonly FilesystemInterface $origin,
1818
private readonly FilesystemInterface $destination,
1919
private readonly ProjectNode $projectNode,
@@ -26,8 +26,8 @@ public function getOutputFormat(): string
2626
return $this->outputFormat;
2727
}
2828

29-
/** @return DocumentNode[] */
30-
public function getDocuments(): array
29+
/** @return iterable<DocumentNode> */
30+
public function getDocuments(): iterable
3131
{
3232
return $this->documents;
3333
}

0 commit comments

Comments
 (0)