Skip to content

Commit

Permalink
Add --installed and --outdated options for module:list command
Browse files Browse the repository at this point in the history
  • Loading branch information
0m3r committed Apr 12, 2023
1 parent 40c5517 commit f296a6a
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion Console/Command/ModuleListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class ModuleListCommand extends Command
const INPUT_OPTION_TYPE = 'type';
const INPUT_OPTION_ALL = 'all';
const INPUT_OPTION_ALL_SHORTCUT = 'a';
const INPUT_OPTION_INSTALLED = 'installed';
const INPUT_OPTION_OUTDATED = 'outdated';

/**
*
Expand Down Expand Up @@ -57,6 +59,20 @@ protected function configure()
'Show all information'
);

$this->addOption(
self::INPUT_OPTION_INSTALLED,
'i',
InputOption::VALUE_NONE,
'Show only installed'
);

$this->addOption(
self::INPUT_OPTION_OUTDATED,
'o',
InputOption::VALUE_NONE,
'Show only outdated'
);

$this->setName('swissup:module:list')
->setDescription('Displays status of swissup modules');
parent::configure();
Expand All @@ -69,6 +85,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
{
$type = $input->getOption(self::INPUT_OPTION_TYPE);
$all = (bool) $input->getOption(self::INPUT_OPTION_ALL);
$showInstalled = (bool) $input->getOption(self::INPUT_OPTION_INSTALLED);
$showOutdated = (bool) $input->getOption(self::INPUT_OPTION_OUTDATED);

if (!in_array($type, ['magento2-module', 'magento2-theme'])) {
$type = 'magento2-' . $type;
Expand Down Expand Up @@ -97,7 +115,16 @@ protected function execute(InputInterface $input, OutputInterface $output)
$row[$key] = isset($item[$key]) ? $item[$key]: '';
}

$color = version_compare($row['version'], $row['latest_version'], '>=') ? 'green' : 'red';
if ($showInstalled && empty($row['version'])) {
continue;
}

$isOutdated = version_compare($row['version'], $row['latest_version'], '<');
if ($showOutdated && !$isOutdated) {
continue;
}

$color = !$isOutdated ? 'green' : 'red';
$row['version'] = "<fg={$color}>{$row['version']}</>";

if (isset($row['release_date'])) {
Expand Down

0 comments on commit f296a6a

Please sign in to comment.