Commit 2831c47c authored by Jon Pugh's avatar Jon Pugh

Finish formatting new `status` command with separate tables for each context.

parent daf76a90
......@@ -3,6 +3,10 @@
namespace Aegir\Provision\Command;
use Aegir\Provision\Command;
use Aegir\Provision\Context;
use Aegir\Provision\Context\PlatformContext;
use Aegir\Provision\Context\ServerContext;
use Aegir\Provision\Context\SiteContext;
use Drupal\Console\Core\Style\DrupalStyle;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputInterface;
......@@ -69,10 +73,14 @@ class StatusCommand extends Command
// Lookup all contexts
$tables = [];
foreach ($this->getProvision()->getAllContexts() as $context) {
$tables[$context->type]['headers'] = [ucfirst($context->type) . 's'];
$tables[$context->type]['rows'][] = [$context->name, $context->type];
$headers['site'] = ['Sites', 'URL', 'Root'];
$headers['server'] = ['Servers', 'services', 'Hostname'];
$headers['platform'] = ['Platforms', 'Root'];
foreach ($this->getProvision()->getAllContexts() as $context) {
$method = "{$context->type}Row";
$tables[$context->type]['rows'][] = $this->$method($context);
}
if (empty($tables)) {
$this->getProvision()->io()->warningLite('There are no contexts. Run <comment>provision save</comment> to get started.');
......@@ -81,7 +89,7 @@ class StatusCommand extends Command
foreach ($tables as $type => $table) {
$this->io->table($table['headers'], $table['rows']);
$this->io->table($headers[$type], $table['rows']);
}
// Offer to output a context status.
......@@ -98,4 +106,54 @@ class StatusCommand extends Command
}
}
}
/**
* Render each server row
*/
private function serverRow(ServerContext $context) {
return [
$context->name,
implode(', ', array_keys($context->getServices())),
$context->getProperty('remote_host'),
];
}
/**
* Render each site row
*/
private function siteRow(SiteContext $context) {
return [
$context->name,
$context->getProperty('uri'),
$context->getProperty('root'),
];
}
/**
* Render each platform row
*/
private function platformRow(PlatformContext $context) {
return [
$context->name,
$context->getProperty('root'),
// $this->sourceCell($context),
];
}
/**
* Format git url and makefile into a single cell.
*
* @param \Aegir\Provision\Context $context
*
* @return array
*/
private function sourceCell(Context $context, $items = []) {
if ($context->getProperty('git_url')) {
$items[] = $context->getProperty('git_url');
}
if ($context->getProperty('makefile')) {
$items[] = $context->getProperty('makefile');
}
return implode("\n", $items);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment