From 91a0002402123b96a08978ba400b5d76d5456693 Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Wed, 27 Sep 2023 11:37:45 +0200 Subject: [PATCH] DumpParametersCommand: `--json` option --- src/Command/DumpParametersCommand.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Command/DumpParametersCommand.php b/src/Command/DumpParametersCommand.php index de3f77cb9e..50e6e57b4b 100644 --- a/src/Command/DumpParametersCommand.php +++ b/src/Command/DumpParametersCommand.php @@ -3,6 +3,7 @@ namespace PHPStan\Command; use Nette\Neon\Neon; +use Nette\Utils\Json; use PHPStan\ShouldNotHappenException; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; @@ -35,6 +36,7 @@ protected function configure(): void new InputOption('autoload-file', 'a', InputOption::VALUE_REQUIRED, 'Project\'s additional autoload file path'), new InputOption('debug', null, InputOption::VALUE_NONE, 'Show debug information - which file is analysed, do not catch internal errors'), new InputOption('memory-limit', null, InputOption::VALUE_REQUIRED, 'Memory limit for clearing result cache'), + new InputOption('json', null, InputOption::VALUE_NONE, 'Dump parameters as JSON instead of NEON'), ]); } @@ -56,6 +58,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $autoloadFile = $input->getOption('autoload-file'); $configuration = $input->getOption('configuration'); $level = $input->getOption(AnalyseCommand::OPTION_LEVEL); + $json = (bool) $input->getOption('json'); if ( (!is_string($memoryLimit) && $memoryLimit !== null) @@ -93,7 +96,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int unset($parameters['tempDir']); unset($parameters['__validate']); - $output->writeln(Neon::encode($parameters, true)); + if ($json) { + $encoded = Json::encode($parameters, Json::PRETTY); + } else { + $encoded = Neon::encode($parameters, true); + } + + $output->writeln($encoded); return 0; }