garvinhicking / clinspector_gadget

Very, very simple TYPO3 console CLI command JSON export
0 stars 0 forks source link

Add Option to pretty-print JSON #1

Closed linawolf closed 1 month ago

linawolf commented 1 month ago

Thanks a lot for this great tool!! Just one small whish: Add Option to pretty-print JSON

This makes working with the JSON files easier and changes are easier to detect in Git

Maybe like this:

protected function execute(InputInterface $input, OutputInterface $output): int
{
    // Capture the current output in a buffer
    $bufferedOutput = new \Symfony\Component\Console\Output\BufferedOutput();

    $helper = new DescriptorHelper();
    $helper->describe(
        $bufferedOutput,
        $this->getApplication(),
        [
            'format' => 'json',
        ]
    );

    // Get the raw JSON output
    $jsonOutput = $bufferedOutput->fetch();

    // Decode and re-encode with pretty print
    $prettyJson = json_encode(json_decode($jsonOutput), JSON_PRETTY_PRINT);

    // Output the prettified JSON
    $output->writeln($prettyJson);

    return Command::SUCCESS;
}
fe-hicking commented 1 month ago

Yes, will do!

garvinhicking commented 1 month ago

I've released 0.1.3 with this fix, thanks!