From dd7d4b56d14c5382281228e686e9f6c389882f75 Mon Sep 17 00:00:00 2001 From: Jaapio Date: Thu, 2 Nov 2023 09:17:14 +0100 Subject: [PATCH] FEAT: show progressbar and output only when not quite --- packages/guides-cli/src/Command/Run.php | 34 +++++++++++++++---------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/packages/guides-cli/src/Command/Run.php b/packages/guides-cli/src/Command/Run.php index 5290de527..23675eebe 100644 --- a/packages/guides-cli/src/Command/Run.php +++ b/packages/guides-cli/src/Command/Run.php @@ -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')); } @@ -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, @@ -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;