50 lines
1.3 KiB
PHP
Raw Normal View History

2016-11-13 16:06:29 +07:00
<?php
2016-11-19 15:13:32 +07:00
/* (c) Anton Medvedev <anton@medv.io>
2016-11-13 16:06:29 +07:00
*
* 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;
2017-03-14 20:16:54 +07:00
desc('Print host configuration');
2016-11-13 16:06:29 +07:00
task('config:dump', function () {
2017-03-14 20:16:54 +07:00
$host = Context::get()->getHost();
$common = Deployer::get()->config;
2017-03-24 21:07:40 +07:00
$config = Context::get()->getConfig();
2016-11-13 16:06:29 +07:00
$dump = [];
2017-03-14 20:16:54 +07:00
foreach ($common as $name => $value) {
2016-11-13 16:06:29 +07:00
try {
2017-03-14 20:16:54 +07:00
$config->get($name);
2016-11-13 16:06:29 +07:00
} catch (\RuntimeException $exception) {
// Ignore fails.
$message = 'Failed to dump';
2017-03-14 20:16:54 +07:00
$config->set($name, output()->isDecorated() ? "\033[1;30m$message\033[0m" : $message);
2016-11-13 16:06:29 +07:00
}
}
2017-03-24 21:07:40 +07:00
foreach ($config->getCollection() as $name => $value) {
2016-11-13 16:06:29 +07:00
if (is_array($value)) {
2017-01-27 20:15:18 +07:00
$value = json_encode($value, JSON_PRETTY_PRINT);
2016-11-13 16:06:29 +07:00
} elseif (is_bool($value)) {
$value = $value ? 'Yes' : 'No';
}
$dump[] = [$name, $value];
}
$io = new SymfonyStyle(input(), output());
2017-03-14 20:16:54 +07:00
$io->section("[{$host->getHostname()}]");
2016-11-13 16:06:29 +07:00
$table = new Table(output());
$table
->setHeaders(['Parameter', 'Value',])
->setRows($dump);
$table->render();
});