From 3efd27c29bf4776999a1dbdd96570f27c8a3bab4 Mon Sep 17 00:00:00 2001 From: Michal Vrchota Date: Fri, 2 Feb 2024 14:00:43 +0100 Subject: [PATCH] Add option to hide progress bar using --no-progress-bar (#79) --- CHANGELOG.md | 4 ++++ README.md | 1 + src/Command/InputSettingData.php | 14 ++++++++++++++ src/Command/YamlCommand.php | 7 +++++-- 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5fe4dad..ccbcbc5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # Changelog ## [Unreleased] +### Added +- [#79] Added option to hide progress bar, Thanks to [@techi602] + ### Changed - [#78] Use system temp dir as default cache dir instead of root of project, Thanks to [@techi602] @@ -248,6 +251,7 @@ patchesJson6902: [@DavidOstrozlik]: https://github.com/DavidOstrozlik [@PetrHeinz]: https://github.com/PetrHeinz +[#79]: https://github.com/sspooky13/yaml-standards/pull/79 [#78]: https://github.com/sspooky13/yaml-standards/pull/78 [#76]: https://github.com/sspooky13/yaml-standards/issues/76 [#72]: https://github.com/sspooky13/yaml-standards/issues/72 diff --git a/README.md b/README.md index deda49b..4735d63 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,7 @@ Tips: - `--fix` Automatically fix allowed standards problems. - `--path-to-cache-dir=./path/to/cache/dir/` Custom path where should be cache file stored. Default is root directory. - `--no-cache` Turn off cache functionality. +- `--no-progress-bar` Turn off progress bar. Useful e.g. for nicer CI output. ## Implemented checkers - **YamlAlphabeticalChecker** - Check yaml file is alphabetically sorted to selected level. **This checker has fixer**. diff --git a/src/Command/InputSettingData.php b/src/Command/InputSettingData.php index 37e17db..a806d8d 100644 --- a/src/Command/InputSettingData.php +++ b/src/Command/InputSettingData.php @@ -28,6 +28,11 @@ class InputSettingData */ private $disableCache; + /** + * @var bool + */ + private $disableProgressBar; + /** * @param \Symfony\Component\Console\Input\InputInterface $input */ @@ -39,6 +44,7 @@ public function __construct(InputInterface $input) $this->fixEnabled = $input->getOption(YamlCommand::OPTION_FIX); $this->pathToCacheDir = $input->getOption(YamlCommand::OPTION_PATH_TO_CACHE_DIR); $this->disableCache = $input->getOption(YamlCommand::OPTION_DISABLE_CACHE); + $this->disableProgressBar = $input->getOption(YamlCommand::OPTION_DISABLE_PROGRESS_BAR); } /** @@ -72,4 +78,12 @@ public function isCacheDisabled(): bool { return $this->disableCache; } + + /** + * @return bool + */ + public function isProgressBarDisabled(): bool + { + return $this->disableProgressBar; + } } diff --git a/src/Command/YamlCommand.php b/src/Command/YamlCommand.php index 86a458f..9d935fc 100644 --- a/src/Command/YamlCommand.php +++ b/src/Command/YamlCommand.php @@ -8,6 +8,7 @@ use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\NullOutput; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; use Symfony\Component\Yaml\Exception\ParseException; @@ -25,6 +26,7 @@ class YamlCommand extends Command public const OPTION_FIX = 'fix'; public const OPTION_PATH_TO_CACHE_DIR = 'path-to-cache-dir'; public const OPTION_DISABLE_CACHE = 'no-cache'; + public const OPTION_DISABLE_PROGRESS_BAR = 'no-progress-bar'; protected static $defaultName = self::COMMAND_NAME; @@ -36,7 +38,8 @@ protected function configure(): void ->addArgument(self::ARGUMENT_PATH_TO_CONFIG_FILE, InputArgument::OPTIONAL, 'Path to configuration file. By default configuration file is looking in root directory', './yaml-standards.yaml') ->addOption(self::OPTION_FIX, null, InputOption::VALUE_NONE, 'Automatically fix problems') ->addOption(self::OPTION_PATH_TO_CACHE_DIR, null, InputOption::VALUE_REQUIRED, 'Custom path to cache dir', sys_get_temp_dir() . '/') - ->addOption(self::OPTION_DISABLE_CACHE, null, InputOption::VALUE_NONE, 'Disable cache functionality'); + ->addOption(self::OPTION_DISABLE_CACHE, null, InputOption::VALUE_NONE, 'Disable cache functionality') + ->addOption(self::OPTION_DISABLE_PROGRESS_BAR, null, InputOption::VALUE_NONE, 'Disable progress bar. Useful e.g. for nicer CI output.'); } /** @@ -52,7 +55,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $cache = $inputSettingData->isCacheDisabled() ? new NoCache() : new NativeCache(); $cache->deleteCacheFileIfConfigFileWasChanged($pathToConfigFile, $pathToCacheDir); - $symfonyStyle = new SymfonyStyle($input, $output); + $symfonyStyle = new SymfonyStyle($input, $inputSettingData->isProgressBarDisabled() ? new NullOutput() : $output); $progressBar = $symfonyStyle->createProgressBar($yamlStandardConfigTotalData->getTotalCountOfFiles()); $progressBar->setFormat('debug'); $results = [[]];