Skip to content

Commit

Permalink
Add --all option to command 'swissup:module:list'
Browse files Browse the repository at this point in the history
  • Loading branch information
0m3r committed Jan 23, 2020
1 parent 7caa129 commit a111f7f
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions Console/Command/ModuleListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
class ModuleListCommand extends Command
{
const INPUT_OPTION_TYPE = 'type';
const INPUT_OPTION_ALL = 'all';
const INPUT_OPTION_ALL_SHORTCUT = 'a';

/**
*
Expand Down Expand Up @@ -48,6 +50,13 @@ protected function configure()
''
);

$this->addOption(
self::INPUT_OPTION_ALL,
self::INPUT_OPTION_ALL_SHORTCUT,
InputOption::VALUE_NONE,
'Show all information'
);

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

if (!in_array($type, ['magento2-module', 'magento2-theme'])) {
$type = 'magento2-' . $type;
Expand All @@ -73,19 +83,30 @@ protected function execute(InputInterface $input, OutputInterface $output)
$rows = [];
$i = 0;
$separator = new TableSeparator();
$columns = explode(',', 'name,code,version,latest_version,type');
if ($all) {
$columns[] = 'release_date';
$columns[] = 'path';
}
foreach ($items as $item) {
if ($type !== false && $item['type'] != $type) {
continue;
}
$row = [];
foreach (explode(',', 'name,code,version,latest_version,type,release_date,path') as $key) {
foreach ($columns as $key) {
$row[$key] = isset($item[$key]) ? $item[$key]: '';
}

$color = version_compare($row['version'], $row['latest_version'], '>=') ? 'green' : 'red';
$row['version'] = "<fg={$color}>{$row['version']}</>";

$row['release_date'] = date("Y-m-d", strtotime($row['release_date']));
if (isset($row['release_date'])) {
$row['release_date'] = date("Y-m-d", strtotime($row['release_date']));
}
if (!empty($row['path']) && strstr($row['path'], '/vendor/')) {
list(, $row['path']) = explode('/vendor/', $row['path']);
$row['path'] = './vendor/' . $row['path'];
}

$rows[] = $row;

Expand All @@ -97,7 +118,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

$table = new Table($output);
$table->setHeaders(['Package', 'Module', 'Version', 'Latest', 'Type', 'Date', 'Path']);
$headers = ['Package', 'Module', 'Version', 'Latest', 'Type'];
if ($all) {
$headers[] = 'Date';
$headers[] = 'Path';
}
$table->setHeaders($headers);
$table->setRows($rows);

$table->render();
Expand Down

0 comments on commit a111f7f

Please sign in to comment.