From 81ba8e303463d4e6f15dd4e9a9cb3859ec864deb Mon Sep 17 00:00:00 2001 From: Anton Medvedev Date: Tue, 14 Mar 2017 20:16:54 +0700 Subject: [PATCH] Add facts --- recipe/common.php | 13 ++++++++++++- recipe/{deploy/config.php => config/dump.php} | 18 +++++++++--------- 2 files changed, 21 insertions(+), 10 deletions(-) rename recipe/{deploy/config.php => config/dump.php} (65%) diff --git a/recipe/common.php b/recipe/common.php index ee68ba77..9a631724 100644 --- a/recipe/common.php +++ b/recipe/common.php @@ -7,7 +7,7 @@ namespace Deployer; -require __DIR__ . '/deploy/config.php'; +require __DIR__ . '/config/dump.php'; require __DIR__ . '/deploy/prepare.php'; require __DIR__ . '/deploy/lock.php'; require __DIR__ . '/deploy/release.php'; @@ -21,9 +21,19 @@ require __DIR__ . '/deploy/cleanup.php'; require __DIR__ . '/deploy/copy_dirs.php'; require __DIR__ . '/deploy/rollback.php'; +use Deployer\Task\Context; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; +/** + * Facts + */ + +set('hostname', function () { + return Context::get()->getHost()->getHostname(); +}); + + /** * Configuration */ @@ -111,6 +121,7 @@ set('bin/symlink', function () { return get('use_relative_symlink') ? 'ln -nfs --relative' : 'ln -nfs'; }); + /** * Default arguments and options. */ diff --git a/recipe/deploy/config.php b/recipe/config/dump.php similarity index 65% rename from recipe/deploy/config.php rename to recipe/config/dump.php index 691d1269..58785ee7 100644 --- a/recipe/deploy/config.php +++ b/recipe/config/dump.php @@ -11,24 +11,24 @@ use Deployer\Task\Context; use Symfony\Component\Console\Helper\Table; use Symfony\Component\Console\Style\SymfonyStyle; -desc('Print server configuration'); +desc('Print host configuration'); task('config:dump', function () { - $server = Context::get()->getHost(); - $config = Deployer::get()->config; - $env = Context::get()->getConfiguration(); + $host = Context::get()->getHost(); + $common = Deployer::get()->config; + $config = Context::get()->getConfiguration(); $dump = []; - foreach ($config as $name => $value) { + foreach ($common as $name => $value) { try { - $env->get($name); + $config->get($name); } catch (\RuntimeException $exception) { // Ignore fails. $message = 'Failed to dump'; - $env->set($name, output()->isDecorated() ? "\033[1;30m$message\033[0m" : $message); + $config->set($name, output()->isDecorated() ? "\033[1;30m$message\033[0m" : $message); } } - foreach ($env->getValues() as $name => $value) { + foreach ($config->getValues() as $name => $value) { if (is_array($value)) { $value = json_encode($value, JSON_PRETTY_PRINT); } elseif (is_bool($value)) { @@ -39,7 +39,7 @@ task('config:dump', function () { } $io = new SymfonyStyle(input(), output()); - $io->section("[{$server->getConfiguration()->getName()}] {$server->getConfiguration()->getHost()}"); + $io->section("[{$host->getHostname()}]"); $table = new Table(output()); $table