Skip to content

Commit

Permalink
Add option to hide progress bar using --no-progress-bar
Browse files Browse the repository at this point in the history
  • Loading branch information
techi602 authored and sspooky13 committed Feb 4, 2024
1 parent ad5bf97 commit 51b2161
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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]

Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**.
Expand Down
14 changes: 14 additions & 0 deletions src/Command/InputSettingData.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ class InputSettingData
*/
private $disableCache;

/**
* @var bool
*/
private $disableProgressBar;

/**
* @param \Symfony\Component\Console\Input\InputInterface $input
*/
Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -72,4 +78,12 @@ public function isCacheDisabled(): bool
{
return $this->disableCache;
}

/**
* @return bool
*/
public function isProgressBarDisabled(): bool
{
return $this->disableProgressBar;
}
}
7 changes: 5 additions & 2 deletions src/Command/YamlCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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.');
}

/**
Expand All @@ -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 = [[]];
Expand Down

0 comments on commit 51b2161

Please sign in to comment.