Feature: console:dump command.

This commit is contained in:
Anton Medvedev 2016-11-13 16:06:29 +07:00
parent 47d2df0190
commit eab095dfd7
3 changed files with 58 additions and 0 deletions

View File

@ -6,6 +6,7 @@
*/
namespace Deployer;
require __DIR__ . '/common/config.php';
use Deployer\Task\Context;
use Symfony\Component\Console\Input\InputArgument;

49
recipe/common/config.php Normal file
View File

@ -0,0 +1,49 @@
<?php
/* (c) Anton Medvedev <anton@elfet.ru>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Deployer;
use Deployer\Task\Context;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Style\SymfonyStyle;
desc('Print server configuration');
task('config:dump', function () {
$server = Context::get()->getServer();
$config = Deployer::get()->config;
$env = Context::get()->getEnvironment();
$dump = [];
foreach ($config as $name => $value) {
try {
$env->get($name);
} catch (\RuntimeException $exception) {
// Ignore fails.
$message = 'Failed to dump';
$env->set($name, output()->isDecorated() ? "\033[1;30m$message\033[0m" : $message);
}
}
foreach ($env->getValues() as $name => $value) {
if (is_array($value)) {
$value = json_encode($value);
} elseif (is_bool($value)) {
$value = $value ? 'Yes' : 'No';
}
$dump[] = [$name, $value];
}
$io = new SymfonyStyle(input(), output());
$io->section("[{$server->getConfiguration()->getName()}] {$server->getConfiguration()->getHost()}");
$table = new Table(output());
$table
->setHeaders(['Parameter', 'Value',])
->setRows($dump);
$table->render();
});

View File

@ -35,6 +35,14 @@ class Environment
$this->values = new Collection();
}
/**
* @return Collection
*/
public function getValues()
{
return $this->values;
}
/**
* @param string $name
* @param bool|int|string|array $value