Skip to content

Commit

Permalink
Merge pull request #648 from phpDocumentor/feature/improve-output-han…
Browse files Browse the repository at this point in the history
…dling

FEAT: show progressbar and output only when not quite
  • Loading branch information
jaapio authored Nov 2, 2023
2 parents 2766064 + b9c510f commit 830c0df
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions packages/guides-cli/src/Command/Run.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,18 @@ public function __construct(
null,
InputOption::VALUE_NEGATABLE,
'Whether to show a progress bar',
true,
);
}

private function getSettingsOverridenWithInput(InputInterface $input): ProjectSettings
{
$settings = $this->settingsManager->getProjectSettings();

if ($settings->isShowProgressBar()) {
$settings->setShowProgressBar($input->getOption('progress'));
}

if ($input->getArgument('input')) {
$settings->setInput((string) $input->getArgument('input'));
}
Expand Down Expand Up @@ -219,13 +225,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$outputFormats = $settings->getOutputFormats();

foreach ($outputFormats as $format) {
$progressBar = null;
$progressBar = null;

if ($output instanceof ConsoleOutputInterface && $settings->isShowProgressBar()) {
$progressBar = new ProgressBar($output->section());
}
if ($output instanceof ConsoleOutputInterface && $settings->isShowProgressBar()) {
$progressBar = new ProgressBar($output->section());
}

foreach ($outputFormats as $format) {
$this->commandBus->handle(
new RenderCommand(
$format,
Expand All @@ -238,17 +244,19 @@ protected function execute(InputInterface $input, OutputInterface $output): int
);
}

$lastFormat = '';
if ($output->isQuiet() === false) {
$lastFormat = '';

if ((is_countable($outputFormats) ? count($outputFormats) : 0) > 1) {
$lastFormat = ((is_countable($outputFormats) ? count($outputFormats) : 0) > 2 ? ',' : '') . ' and ' . strtoupper((string) array_pop($outputFormats));
}
if ((is_countable($outputFormats) ? count($outputFormats) : 0) > 1) {
$lastFormat = ((is_countable($outputFormats) ? count($outputFormats) : 0) > 2 ? ',' : '') . ' and ' . strtoupper((string) array_pop($outputFormats));
}

$formatsText = strtoupper(implode(', ', $outputFormats)) . $lastFormat;
$formatsText = strtoupper(implode(', ', $outputFormats)) . $lastFormat;

$output->writeln(
'Successfully placed ' . (is_countable($documents) ? count($documents) : 0) . ' rendered ' . $formatsText . ' files into ' . $outputDir,
);
$output->writeln(
'Successfully placed ' . (is_countable($documents) ? count($documents) : 0) . ' rendered ' . $formatsText . ' files into ' . $outputDir,
);
}

if ($settings->isFailOnError() && $spyProcessor->hasBeenCalled()) {
return Command::FAILURE;
Expand Down

0 comments on commit 830c0df

Please sign in to comment.