Packages/CreateReferenceCommand/src/Command/CommandReferenceRenderCommand.php
protected function renderReference(OutputInterface $output): int
    {
        putenv('TYPO3_CONSOLE_RENDERING_REFERENCE=1');
        $_SERVER['PHP_SELF'] = Application::COMMAND_NAME;
        $application = $this->getApplication();
        $applicationDescription = new ApplicationDescription($application, null, true);
        $commands = $applicationDescription->getCommands();
        $allCommands = [];
        foreach ($commands as $command) {
            if (in_array($command->getName(), $this->skipCommands, true)) {
                continue;
            }

            $argumentDescriptions = [];
            $optionDescriptions = [];
            $command->mergeApplicationDefinition(false);
            $commandDefinition = $command->getNativeDefinition();
            foreach ($commandDefinition->getArguments() as $argument) {
                $argumentDescriptions[$argument->getName()] = $this->transformMarkup($argument->getDescription());
            }

            foreach ($commandDefinition->getOptions() as $option) {
                if ($application->getDefinition()->hasOption($option->getName())) {
                    // We don't want global options to be rendered multiple times in the reference
                    continue;
                }
                $optionDescriptions[$this->getOptionName($option)] = [
                    'description' => $this->transformMarkup($option->getDescription()),
                    'acceptValue' => $option->acceptValue() ? 'yes' : 'no',
                    'isValueRequired' => $option->isValueRequired() ? 'yes' : 'no',
                    'isMultiple' => $option->isArray() ? 'yes' : 'no',
                    'default' => str_replace(["\n", TYPO3_version], ['', '<Current-TYPO3-Version>'], var_export($option->getDefault(), true)),
                ];
            }

            $relatedCommands = [];
            if (is_callable([$command, 'getRelatedCommandNames'])) {
                $relatedCommandIdentifiers = $command->getRelatedCommandNames();
                foreach ($relatedCommandIdentifiers as $relatedCommandIdentifier) {
                    $commandParts = explode(':', $relatedCommandIdentifier);
                    $shortCommandIdentifier = $relatedCommandIdentifier;
                    if (count($commandParts) === 3) {
                        $shortCommandIdentifier = $commandParts[1] . ':' . $commandParts[2];
                    }
                    if (isset($commands[$relatedCommandIdentifier])) {
                        $relatedCommand = $commands[$relatedCommandIdentifier];
                        $relatedCommands[$relatedCommandIdentifier] = $relatedCommand->getDescription();
                    } elseif (isset($commands[$shortCommandIdentifier])) {
                        $relatedCommand = $commands[$shortCommandIdentifier];
                        $relatedCommands[$shortCommandIdentifier] = $relatedCommand->getDescription();
                    } else {
                        $relatedCommands[$relatedCommandIdentifier] = '*Command not available*';
                    }
                }
            }

            $allCommands[$command->getName()] = [
                'identifier' => $command->getName(),
                'shortDescription' => $this->transformMarkup($command->getDescription()),
                'description' => $this->transformMarkup($command->getHelp() ? $command->getProcessedHelp() : ''),
                'options' => $optionDescriptions,
                'arguments' => $argumentDescriptions,
                'relatedCommands' => $relatedCommands,
            ];
        }

        $applicationOptions = [];
        foreach ($application->getDefinition()->getOptions() as $option) {
            $applicationOptions[$this->getOptionName($option)] = [
                'description' => $this->transformMarkup($option->getDescription()),
                'acceptValue' => $option->acceptValue() ? 'yes' : 'no',
                'isValueRequired' => $option->isValueRequired() ? 'yes' : 'no',
                'isMultiple' => $option->isArray() ? 'yes' : 'no',
                'default' => str_replace("\n", '', var_export($option->getDefault(), true)),
            ];
        }

        $standaloneView = new StandaloneView();
        $templatePathAndFilename = __DIR__ . '/../../Resources/Templates/CommandReferenceTemplate.txt';
        $standaloneView->setTemplatePathAndFilename($templatePathAndFilename);
        $standaloneView->assignMultiple(
            [
                'title' => 'Command Reference',
                'commandName' => Application::COMMAND_NAME,
                'applicationOptions' => $applicationOptions,
                'allCommandsByPackageKey' => ['typo3_console' => $allCommands],
            ]
        );

        $renderedOutputFile = getenv('TYPO3_PATH_COMPOSER_ROOT') . '/Documentation/CommandReference/Index.rst';
        file_put_contents($renderedOutputFile, $standaloneView->render());
        $output->writeln('DONE.');

        return 0;
    }
protected function renderReference(OutputInterface $output): int
    {
        putenv('TYPO3_CONSOLE_RENDERING_REFERENCE=1');
        $_SERVER['PHP_SELF'] = Application::COMMAND_NAME;
        $application = $this->getApplication();
        $applicationDescription = new ApplicationDescription($application, null, true);
        $commands = $applicationDescription->getCommands();
        $allCommands = [];
        foreach ($commands as $command) {
            if (in_array($command->getName(), $this->skipCommands, true)) {
                continue;
            }

            $argumentDescriptions = [];
            $optionDescriptions = [];
            $command->mergeApplicationDefinition(false);
            $commandDefinition = $command->getNativeDefinition();
            foreach ($commandDefinition->getArguments() as $argument) {
                $argumentDescriptions[$argument->getName()] = $this->transformMarkup($argument->getDescription());
            }

            foreach ($commandDefinition->getOptions() as $option) {
                if ($application->getDefinition()->hasOption($option->getName())) {
                    // We don't want global options to be rendered multiple times in the reference
                    continue;
                }
                $optionDescriptions[$this->getOptionName($option)] = [
                    'description' => $this->transformMarkup($option->getDescription()),
                    'acceptValue' => $option->acceptValue() ? 'yes' : 'no',
                    'isValueRequired' => $option->isValueRequired() ? 'yes' : 'no',
                    'isMultiple' => $option->isArray() ? 'yes' : 'no',
                    'default' => str_replace(["\n", TYPO3_version], ['', '<Current-TYPO3-Version>'], var_export($option->getDefault(), true)),
                ];
            }

            $relatedCommands = [];
            if (is_callable([$command, 'getRelatedCommandNames'])) {
                $relatedCommandIdentifiers = $command->getRelatedCommandNames();
                foreach ($relatedCommandIdentifiers as $relatedCommandIdentifier) {
                    $commandParts = explode(':', $relatedCommandIdentifier);
                    $shortCommandIdentifier = $relatedCommandIdentifier;
                    if (count($commandParts) === 3) {
                        $shortCommandIdentifier = $commandParts[1] . ':' . $commandParts[2];
                    }
                    if (isset($commands[$relatedCommandIdentifier])) {
                        $relatedCommand = $commands[$relatedCommandIdentifier];
                        $relatedCommands[$relatedCommandIdentifier] = $relatedCommand->getDescription();
                    } elseif (isset($commands[$shortCommandIdentifier])) {
                        $relatedCommand = $commands[$shortCommandIdentifier];
                        $relatedCommands[$shortCommandIdentifier] = $relatedCommand->getDescription();
                    } else {
                        $relatedCommands[$relatedCommandIdentifier] = '*Command not available*';
                    }
                }
            }

            $allCommands[$command->getName()] = [
                'identifier' => $command->getName(),
                'shortDescription' => $this->transformMarkup($command->getDescription()),
                'description' => $this->transformMarkup($command->getHelp() ? $command->getProcessedHelp() : ''),
                'options' => $optionDescriptions,
                'arguments' => $argumentDescriptions,
                'relatedCommands' => $relatedCommands,
            ];
        }

        $applicationOptions = [];
        foreach ($application->getDefinition()->getOptions() as $option) {
            $applicationOptions[$this->getOptionName($option)] = [
                'description' => $this->transformMarkup($option->getDescription()),
                'acceptValue' => $option->acceptValue() ? 'yes' : 'no',
                'isValueRequired' => $option->isValueRequired() ? 'yes' : 'no',
                'isMultiple' => $option->isArray() ? 'yes' : 'no',
                'default' => str_replace("\n", '', var_export($option->getDefault(), true)),
            ];
        }

        $standaloneView = new StandaloneView();
        $templatePathAndFilename = __DIR__ . '/../../Resources/Templates/CommandReferenceTemplate.txt';
        $standaloneView->setTemplatePathAndFilename($templatePathAndFilename);
        $standaloneView->assignMultiple(
            [
                'title' => 'Command Reference',
                'commandName' => Application::COMMAND_NAME,
                'applicationOptions' => $applicationOptions,
                'allCommandsByPackageKey' => ['typo3_console' => $allCommands],
            ]
        );

        $renderedOutputFile = getenv('TYPO3_PATH_COMPOSER_ROOT') . '/Documentation/CommandReference/Index.rst';
        file_put_contents($renderedOutputFile, $standaloneView->render());
        $output->writeln('DONE.');

        return 0;
    }
Render a CLI command reference to reStructuredText.

@param OutputInterface $output
@return int