mirror of
https://github.com/deployphp/deployer.git
synced 2025-02-24 09:12:51 +01:00
Feature: console:dump command.
This commit is contained in:
parent
47d2df0190
commit
eab095dfd7
@ -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
49
recipe/common/config.php
Normal 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();
|
||||
});
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user