Skip to content

Commit a241073

Browse files
committed
Tightening up progress bar and removing non-functional one
1 parent 5e1032b commit a241073

File tree

1 file changed

+25
-20
lines changed

1 file changed

+25
-20
lines changed

src/Command/CommandInitializerTrait.php

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Doctrine\RST\Builder;
77
use Doctrine\RST\Event\PostNodeRenderEvent;
88
use Doctrine\RST\Event\PostParseDocumentEvent;
9+
use Doctrine\RST\Event\PreBuildParseEvent;
910
use Doctrine\RST\Event\PreBuildRenderEvent;
1011
use Symfony\Component\Console\Helper\ProgressBar;
1112
use Symfony\Component\Console\Input\InputInterface;
@@ -126,10 +127,19 @@ private function getRealAbsolutePath(string $path, Filesystem $filesystem): stri
126127

127128
private function initializeProgressBarEventListeners(): void
128129
{
130+
// sets up the "parsing" progress bar
131+
$this->eventManager->addEventListener(
132+
[PreBuildParseEvent::PRE_BUILD_PARSE],
133+
$this
134+
);
135+
136+
// advances "parsing" progress bar
129137
$this->eventManager->addEventListener(
130138
[PostParseDocumentEvent::POST_PARSE_DOCUMENT],
131139
$this
132140
);
141+
142+
// tries to handle progress bar for "rendering"
133143
$this->eventManager->addEventListener(
134144
[PreBuildRenderEvent::PRE_BUILD_RENDER],
135145
$this
@@ -145,9 +155,6 @@ private function startBuild()
145155

146156
$this->sanitizeOutputDirs($this->finder);
147157

148-
$this->io->note(sprintf('Start parsing %d rst files', $this->finder->count()));
149-
$this->progressBar = new ProgressBar($this->output, $this->finder->count());
150-
151158
$this->builder->build(
152159
$this->buildContext->getSourceDir(),
153160
$this->buildContext->getHtmlOutputDir()
@@ -205,6 +212,19 @@ private function isCacheDisabled(): bool
205212
return $this->input->hasOption('disable-cache') && (bool) $this->input->getOption('disable-cache');
206213
}
207214

215+
/**
216+
* Called very early: used to initialize the "parsing" progress bar.
217+
*
218+
* @param PreBuildParseEvent $event
219+
*/
220+
public function preBuildParse(PreBuildParseEvent $event)
221+
{
222+
$parseQueue = $event->getParseQueue();
223+
$parseCount = count($parseQueue->getAllFilesThatRequireParsing());
224+
$this->io->note(sprintf('Start parsing %d out-of-date rst files', $parseCount));
225+
$this->progressBar = new ProgressBar($this->output, $parseCount);
226+
}
227+
208228
public function postParseDocument(PostParseDocumentEvent $postParseDocumentEvent): void
209229
{
210230
$file = $postParseDocumentEvent->getDocumentNode()->getEnvironment()->getCurrentFileName();
@@ -216,25 +236,10 @@ public function postParseDocument(PostParseDocumentEvent $postParseDocumentEvent
216236

217237
public function doPreBuildRender()
218238
{
219-
$this->eventManager->removeEventListener(
220-
[PostParseDocumentEvent::POST_PARSE_DOCUMENT],
221-
$this
222-
);
223-
239+
// finishes the "parse" progress bar
224240
$this->progressBar->finish();
225241

226-
$this->progressBar = new ProgressBar($this->output);
227-
228-
$this->eventManager->addEventListener(
229-
[PostNodeRenderEvent::POST_NODE_RENDER],
230-
$this
231-
);
232-
233242
$this->io->newLine(2);
234-
}
235-
236-
public function postNodeRender(): void
237-
{
238-
$this->progressBar->advance();
243+
// TODO: create a proper progress bar for rendering
239244
}
240245
}

0 commit comments

Comments
 (0)