/** * Print and save drush aliases * * ## OPTIONS * * [--print] * : print aliases to screen * * [--location=<location>] * : specify the location of the alias file, default it ~/.drush/pantheon.drushrc.php * */ public function aliases($args, $assoc_args) { $user = new User(); $print = Input::optional('print', $assoc_args, false); $json = \Terminus::get_config('json'); $location = Input::optional('location', $assoc_args, getenv("HOME") . '/.drush/pantheon.aliases.drushrc.php'); $message = "Pantheon aliases updated."; if (!file_exists($location)) { $message = "Pantheon aliases created."; } $content = $user->getAliases(); $h = fopen($location, 'w+'); fwrite($h, $content); fclose($h); chmod($location, 0777); Logger::coloredOutput("%2%K{$message}%n"); if ($json) { include $location; print \Terminus\Utils\json_dump($aliases); } elseif ($print) { print $content; } }
/** * Hostname operations * * ## OPTIONS * * <list|add|remove> * : OPTIONS are list, add, delete * * [--site=<site>] * : Site to use * * --env=<env> * : environment to use * * [--hostname=<hostname>] * : hostname to add * */ public function hostnames($args, $assoc_args) { $action = array_shift($args); $site = SiteFactory::instance(Input::site($assoc_args)); $env = Input::env($assoc_args, 'env'); switch ($action) { case 'list': $hostnames = $data = (array) $site->environment($env)->hostnames(); if (!Terminus::get_config('json')) { // if were not just dumping the json then we should reformat the data $data = array(); foreach ($hostnames as $hostname => $details) { $data[] = array_merge(array('domain' => $hostname), (array) $details); } } $this->handleDisplay($data); break; case 'add': if (!isset($assoc_args['hostname'])) { Terminus::error("Must specify hostname with --hostname"); } $data = $site->environment($env)->hostnameadd($assoc_args['hostname']); if (Terminus::get_config('verbose')) { \Terminus\Utils\json_dump($data); } Terminus::success("Added %s to %s-%s", array($assoc_args['hostname'], $site->getName(), $env)); break; case 'remove': if (!isset($assoc_args['hostname'])) { Terminus::error("Must specify hostname with --hostname"); } $data = $site->environment($env)->hostnamedelete($assoc_args['hostname']); Terminus::success("Deleted %s from %s-%s", array($assoc_args['hostname'], $site->getName(), $env)); break; } return $data; }
/** * Decides and handles how to display data going to STDOUT * * @param [string] $data Data for display * @param [array] $args Instructions on how to display data * @param [array] $headers Table headers * @return [void] */ protected function handleDisplay($data, $args = array(), $headers = null) { if (array_key_exists('json', $args) || Terminus::get_config('json')) { echo \Terminus\Utils\json_dump($data); } elseif (array_key_exists('bash', $args) || Terminus::get_config('bash')) { echo \Terminus\Utils\bash_out((array) $data); } else { $this->constructTableForResponse((array) $data, $headers); } }
/** * Dump session data * @subcommand session-dump */ public function session_dump() { $session = $this->cache->get_data("session"); echo \Terminus\Utils\json_dump($session); }
/** * Print and save drush aliases * * ## OPTIONS * * [--print] * : print aliases to screen * * [--location=<location>] * : Specify the the full path, including the filename, to the alias file you wish to create. * Without this option a default of '~/.drush/pantheon.drushrc.php' will be used. * */ public function aliases($args, $assoc_args) { $user = new User(new stdClass(), array()); $print = Input::optional('print', $assoc_args, false); $json = \Terminus::get_config('json'); $location = Input::optional('location', $assoc_args, getenv("HOME") . '/.drush/pantheon.aliases.drushrc.php'); // Cannot provide just a directory if (is_dir($location)) { \Terminus::error("Please provide a full path with filename, e.g. %s/pantheon.aliases.drushrc.php", $location); exit(1); } $file_exists = file_exists($location); // Create the directory if it doesn't yet exist $dirname = dirname($location); if (!is_dir($dirname)) { mkdir($dirname, 0700, true); } $content = $user->getAliases(); $h = fopen($location, 'w+'); fwrite($h, $content); fclose($h); chmod($location, 0700); $message = $file_exists ? 'Pantheon aliases updated' : 'Pantheon aliases created'; Logger::coloredOutput("%2%K{$message}%n"); if ($json) { include $location; print \Terminus\Utils\json_dump($aliases); } elseif ($print) { print $content; } }
/** * Hostname operations * * ## OPTIONS * * <list|add|remove> * : OPTIONS are list, add, delete * * [--site=<site>] * : Site to use * * --env=<env> * : environment to use * * [--hostname=<hostname>] * : hostname to add * */ public function hostnames($args, $assoc_args) { $action = array_shift($args); $site = $this->sites->get(Input::sitename($assoc_args)); $env = $site->environments->get(Input::env($assoc_args, 'env')); switch ($action) { case 'list': $hostnames = $env->getHostnames(); $data = $hostnames; if (!Terminus::get_config('json')) { //If were not just dumping the JSON, then we should reformat the data. $data = array(); foreach ($hostnames as $hostname => $details) { $data[] = array_merge(array('domain' => $hostname), (array) $details); } } $this->outputter->outputRecordList($data); break; case 'add': if (!isset($assoc_args['hostname'])) { Terminus::error('Must specify hostname with --hostname'); } $data = $env->addHostname($assoc_args['hostname']); if (Terminus::get_config('verbose')) { \Terminus\Utils\json_dump($data); } Terminus::success('Added %s to %s-%s', array($assoc_args['hostname'], $site->get('name'), $env->get('id'))); break; case 'remove': if (!isset($assoc_args['hostname'])) { Terminus::error('Must specify hostname with --hostname'); } $data = $env->deleteHostname($assoc_args['hostname']); Terminus::success('Deleted %s from %s-%s', array($assoc_args['hostname'], $site->get('name'), $env->get('id'))); break; } return $data; }