Skip to content

Commit

Permalink
DumpParametersCommand: --json option
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Sep 27, 2023
1 parent 5b6b854 commit 91a0002
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Command/DumpParametersCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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'),
]);
}

Expand All @@ -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)
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 91a0002

Please sign in to comment.