[FEATURE] Show extensions via CLI 94/58094/6
authorBenni Mack <benni@typo3.org>
Fri, 31 Aug 2018 07:19:01 +0000 (09:19 +0200)
committerFrans Saris <franssaris@gmail.com>
Fri, 31 Aug 2018 09:09:20 +0000 (11:09 +0200)
A new Symfony command "extension:list" allows to list all active
extensions.

Using --all option also includes the currently inactive extensions
available for installation and --inactive only shows the currently
inactive extensions available for installation.

Additional description of the extensions can be shown by --verbose / -v.

Resolves: #86051
Releases: master
Change-Id: I88a370a1c2a0b7a850e2e99afba3a992d4dee661
Reviewed-on: https://review.typo3.org/58094
Reviewed-by: Kevin Appelt <kevin.appelt@icloud.com>
Tested-by: Kevin Appelt <kevin.appelt@icloud.com>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Frans Saris <franssaris@gmail.com>
Tested-by: Frans Saris <franssaris@gmail.com>
typo3/sysext/core/Classes/Command/ExtensionListCommand.php [new file with mode: 0644]
typo3/sysext/core/Configuration/Commands.php
typo3/sysext/core/Documentation/Changelog/master/Feature-86051-ShowExtensionsViaCLI.rst [new file with mode: 0644]

diff --git a/typo3/sysext/core/Classes/Command/ExtensionListCommand.php b/typo3/sysext/core/Classes/Command/ExtensionListCommand.php
new file mode 100644 (file)
index 0000000..2042aac
--- /dev/null
@@ -0,0 +1,118 @@
+<?php
+declare(strict_types = 1);
+namespace TYPO3\CMS\Core\Command;
+
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+use Symfony\Component\Console\Command\Command;
+use Symfony\Component\Console\Helper\Table;
+use Symfony\Component\Console\Helper\TableCell;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Input\InputOption;
+use Symfony\Component\Console\Output\OutputInterface;
+use Symfony\Component\Console\Style\SymfonyStyle;
+use TYPO3\CMS\Core\Package\PackageManager;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+
+/**
+ * Command for listing all extensions known to the system.
+ *
+ * If the command is called with the verbose option, also shows the description of the package.
+ */
+class ExtensionListCommand extends Command
+{
+    /**
+     * Defines the allowed options for this command
+     */
+    protected function configure()
+    {
+        $this
+            ->setDescription('Shows the list of extensions available to the system.')
+            ->addOption(
+                'all',
+                'a',
+                InputOption::VALUE_NONE,
+                'Also display currently inactive/uninstalled extensions.'
+            )
+            ->addOption(
+                'inactive',
+                'i',
+                InputOption::VALUE_NONE,
+                'Only show inactive/uninstalled extensions available for installation.'
+            );
+    }
+
+    /**
+     * Shows the list of all extensions
+     *
+     * @inheritdoc
+     */
+    protected function execute(InputInterface $input, OutputInterface $output)
+    {
+        $io = new SymfonyStyle($input, $output);
+        $packageManager = GeneralUtility::makeInstance(PackageManager::class);
+
+        $onlyShowInactiveExtensions = $input->getOption('inactive');
+        $showAlsoInactiveExtensions = $input->getOption('all');
+        if ($onlyShowInactiveExtensions) {
+            $packages = $packageManager->getAvailablePackages();
+            $io->title('All inactive/currently uninstalled extensions');
+        } elseif ($showAlsoInactiveExtensions) {
+            $packages = $packageManager->getAvailablePackages();
+            $io->title('All installed (= active) and available (= inactive/currently uninstalled) extensions');
+        } else {
+            $packages = $packageManager->getActivePackages();
+            $io->title('All installed (= active) extensions');
+        }
+
+        $table = new Table($output);
+        $table->setHeaders([
+            'Extension Key',
+            'Version',
+            'Type',
+            'Status',
+        ]);
+        $table->setColumnWidths([30, 10, 8, 6]);
+
+        $formatter = $this->getHelper('formatter');
+        foreach ($packages as $package) {
+            $isActivePackage = $packageManager->isPackageActive($package->getPackageKey());
+            // Do not show the package if it is active but we only want to see inactive packages
+            if ($onlyShowInactiveExtensions && $isActivePackage) {
+                continue;
+            }
+            if ($package->getValueFromComposerManifest('type') === 'typo3-cms-framework') {
+                $type = 'System';
+            } else {
+                $type = 'Local';
+            }
+
+            // Ensure that the inactive extensions are shown as well
+            if ($onlyShowInactiveExtensions || ($showAlsoInactiveExtensions && !$isActivePackage)) {
+                $status = '<comment>inactive</comment>';
+            } else {
+                $status = '<info>active</info>';
+            }
+
+            $table->addRow([$package->getPackageKey(), $package->getPackageMetaData()->getVersion(), $type, $status]);
+
+            // Also show the description of the extension, if verbose option is set
+            if ($output->isVerbose()) {
+                $description = (string)$package->getValueFromComposerManifest('description');
+                $table->addRow([new TableCell('    ' . $formatter->truncate($description, 80) . "\n\n", ['colspan' => 4])]);
+            }
+        }
+        $table->render();
+    }
+}
index e182800..9c450fc 100644 (file)
@@ -8,4 +8,8 @@ return [
     'swiftmailer:spool:send' => [
         'class' => \TYPO3\CMS\Core\Command\SendEmailCommand::class,
     ],
+    'extension:list' => [
+        'class' => \TYPO3\CMS\Core\Command\ExtensionListCommand::class,
+        'schedulable' => false
+    ],
 ];
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Feature-86051-ShowExtensionsViaCLI.rst b/typo3/sysext/core/Documentation/Changelog/master/Feature-86051-ShowExtensionsViaCLI.rst
new file mode 100644 (file)
index 0000000..76efb0c
--- /dev/null
@@ -0,0 +1,28 @@
+.. include:: ../../Includes.txt
+
+=========================================
+Feature: #86051 - Show extensions via CLI
+=========================================
+
+See :issue:`86051`
+
+Description
+===========
+
+A new command `extension:list` is added, which can be executed via Command Line
+`typo3/sysext/core/bin/typo3 extension:list`.
+
+This command shows all currently installed (= active) extensions. The option `--all`
+also includes all inactive extensions. If only the list of inactive extensions should
+be shown, the command `--inactive` will show only the extensions available for installation.
+
+Additional description of the extensions can be shown by --verbose / -v.
+
+
+Impact
+======
+
+In order to show which extensions can be uninstalled or installed via CLI, the new command
+is a good companion for the existing commands `extension:activate` and `extension:deactivate`.
+
+.. index:: CLI, ext:core
\ No newline at end of file