Skip to content

Commit

Permalink
Merge pull request #1099 from helhum/migrate-full-boot-commands
Browse files Browse the repository at this point in the history
  • Loading branch information
helhum committed Feb 25, 2023
2 parents a1c1684 + 4100319 commit e8ca3c5
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 67 deletions.
32 changes: 0 additions & 32 deletions Configuration/Commands.php
Expand Up @@ -2,26 +2,6 @@
declare(strict_types=1);

return [
'backend:createadmin' => [
'vendor' => 'typo3_console',
'class' => \Helhum\Typo3Console\Command\Backend\CreateBackendAdminUserCommand::class,
],
'backend:lockforeditors' => [
'vendor' => 'typo3_console',
'class' => \Helhum\Typo3Console\Command\Backend\LockBackendForEditorsCommand::class,
],
'backend:unlockforeditors' => [
'vendor' => 'typo3_console',
'class' => \Helhum\Typo3Console\Command\Backend\UnlockBackendForEditorsCommand::class,
],
'cache:flushtags' => [
'vendor' => 'typo3_console',
'class' => \Helhum\Typo3Console\Command\Cache\CacheFlushTagsCommand::class,
],
'cache:listgroups' => [
'vendor' => 'typo3_console',
'class' => \Helhum\Typo3Console\Command\Cache\CacheListGroupsCommand::class,
],
'configuration:remove' => [
'vendor' => 'typo3_console',
'class' => \Helhum\Typo3Console\Command\Configuration\ConfigurationRemoveCommand::class,
Expand All @@ -32,14 +12,6 @@
'class' => \Helhum\Typo3Console\Command\Configuration\ConfigurationSetCommand::class,
'runLevel' => \Helhum\Typo3Console\Core\Booting\RunLevel::LEVEL_MINIMAL,
],
'configuration:show' => [
'vendor' => 'typo3_console',
'class' => \Helhum\Typo3Console\Command\Configuration\ConfigurationShowCommand::class,
],
'configuration:showactive' => [
'vendor' => 'typo3_console',
'class' => \Helhum\Typo3Console\Command\Configuration\ConfigurationShowActiveCommand::class,
],
'configuration:showlocal' => [
'vendor' => 'typo3_console',
'class' => \Helhum\Typo3Console\Command\Configuration\ConfigurationShowLocalCommand::class,
Expand All @@ -63,10 +35,6 @@
'helhum.typo3console:persistence',
],
],
'frontend:request' => [
'vendor' => 'typo3_console',
'class' => \Helhum\Typo3Console\Command\Frontend\FrontendRequestCommand::class,
],
'install:setup' => [
'vendor' => 'typo3_console',
'class' => \Helhum\Typo3Console\Command\Install\InstallSetupCommand::class,
Expand Down
64 changes: 64 additions & 0 deletions Configuration/Services.yaml
@@ -0,0 +1,64 @@
services:
_defaults:
autowire: true
autoconfigure: true
public: false

Helhum\Typo3Console\:
resource: '../Classes/Console/*'

Helhum\Typo3Console\Command\Backend\CreateBackendAdminUserCommand:
tags:
-
name: 'console.command'
command: 'backend:createadmin'
description: 'Create admin backend user'

Helhum\Typo3Console\Command\Backend\LockBackendForEditorsCommand:
tags:
-
name: 'console.command'
command: 'backend:lockforeditors'
description: 'Lock backend for editors'

Helhum\Typo3Console\Command\Backend\UnlockBackendForEditorsCommand:
tags:
-
name: 'console.command'
command: 'backend:unlockforeditors'
description: 'Unlock backend for editors'

Helhum\Typo3Console\Command\Cache\CacheFlushTagsCommand:
tags:
-
name: 'console.command'
command: 'cache:flushtags'
description: 'Flush cache by tags'

Helhum\Typo3Console\Command\Cache\CacheListGroupsCommand:
tags:
-
name: 'console.command'
command: 'cache:listgroups'
description: 'List cache groups'

Helhum\Typo3Console\Command\Configuration\ConfigurationShowCommand:
tags:
-
name: 'console.command'
command: 'configuration:show'
description: 'Show configuration value'

Helhum\Typo3Console\Command\Configuration\ConfigurationShowActiveCommand:
tags:
-
name: 'console.command'
command: 'configuration:showactive'
description: 'Show active configuration value'

Helhum\Typo3Console\Command\Frontend\FrontendRequestCommand:
tags:
-
name: 'console.command'
command: 'frontend:request'
description: 'Submit frontend request'
Expand Up @@ -25,8 +25,6 @@
* */

use Helhum\Typo3Console\Command\RelatableCommandInterface;
use Helhum\Typo3Console\Mvc\Cli\CommandCollection;
use Helhum\Typo3Console\Mvc\Cli\CommandConfiguration;
use Helhum\Typo3Console\Mvc\Cli\Symfony\Application;
use Symfony\Component\Console\Descriptor\ApplicationDescription;
use Symfony\Component\Console\Input\InputArgument;
Expand All @@ -36,14 +34,49 @@
use Symfony\Component\Console\Output\OutputInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Fluid\View\StandaloneView;
use Typo3Console\CreateReferenceCommand\EmptyTypo3CommandRegistry;

/**
* "Command Reference" command controller for the Documentation package.
* Used to create reference documentation for TYPO3 Console CLI commands.
*/
class CommandReferenceRenderCommand extends \Symfony\Component\Console\Command\Command
{
private const consoleCommands = [
'backend:createadmin',
'backend:lockforeditors',
'backend:unlockforeditors',
'cache:flushtags',
'cache:listgroups',
'configuration:remove',
'configuration:set',
'configuration:show',
'configuration:showactive',
'configuration:showlocal',
'database:export',
'database:import',
'database:updateschema',
'frontend:request',
'install:setup',
'install:generatepackagestates',
'install:fixfolderstructure',
'install:extensionsetupifpossible',
'install:environmentandfolders',
'install:databaseconnect',
'install:databaseselect',
'install:databasedata',
'install:defaultconfiguration',
'install:actionneedsexecution',
'install:lock',
'install:unlock',
'upgrade:checkextensioncompatibility',
'upgrade:checkextensionconstraints',
'upgrade:list',
'upgrade:prepare',
'upgrade:run',
'help',
'list',
];

private $skipCommands = [
'server:run',
];
Expand Down Expand Up @@ -90,35 +123,16 @@ protected function renderReference(OutputInterface $output): int
$commandReferenceDir = getenv('TYPO3_PATH_COMPOSER_ROOT') . '/Documentation/CommandReference/';
GeneralUtility::rmdir($commandReferenceDir, true);
GeneralUtility::mkdir($commandReferenceDir);
$commandCollection = new CommandCollection(new CommandConfiguration(), new EmptyTypo3CommandRegistry());
$application = new class($this->getApplication()) extends \Symfony\Component\Console\Application {
/**
* @var Application
*/
private $application;

public function __construct(Application $application, string $name = 'UNKNOWN', string $version = 'UNKNOWN')
{
parent::__construct($name, $version);
$this->application = $application;
}

protected function getDefaultInputDefinition()
{
return $this->application->getDefaultInputDefinition();
}

protected function getDefaultCommands()
{
return $this->application->getDefaultCommands();
}
};
$application->setCommandLoader($commandCollection);
$application = $this->getApplication();
assert($application instanceof Application);
$applicationDescription = new ApplicationDescription($application, null, true);
$commands = $applicationDescription->getCommands();
$allCommands = [];
foreach ($commands as $command) {
if (in_array($command->getName(), $this->skipCommands, true)) {
$commandName = $command->getName();
if (in_array($commandName, $this->skipCommands, true)
|| !in_array($commandName, self::consoleCommands, true)
) {
continue;
}

Expand Down Expand Up @@ -164,24 +178,23 @@ protected function getDefaultCommands()
}
}
}

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

$standaloneView = new StandaloneView();
$templatePathAndFilename = __DIR__ . '/../../Resources/Templates/CommandTemplate.txt';
$standaloneView->setTemplatePathAndFilename($templatePathAndFilename);
$standaloneView->assignMultiple(['command' => $allCommands[$command->getName()]]);
$standaloneView->assignMultiple(['command' => $allCommands[$commandName]]);

$renderedOutputFile = $commandReferenceDir . $allCommands[$command->getName()]['docDirectory'] . '.rst';
$renderedOutputFile = $commandReferenceDir . $allCommands[$commandName]['docDirectory'] . '.rst';
file_put_contents($renderedOutputFile, $standaloneView->render());
}

Expand Down

0 comments on commit e8ca3c5

Please sign in to comment.