From af7104c0ba998691f071bca55a49a94e061e0f37 Mon Sep 17 00:00:00 2001 From: Adam Malone Date: Sun, 18 Oct 2020 12:39:37 +1100 Subject: [PATCH] Adds first pass at domain list/info and account in json. --- src/Cli/AcquiaCli.php | 7 +++++++ src/Commands/AccountCommand.php | 7 +++++-- src/Commands/DomainCommand.php | 7 +++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/Cli/AcquiaCli.php b/src/Cli/AcquiaCli.php index e55928b..7175b42 100644 --- a/src/Cli/AcquiaCli.php +++ b/src/Cli/AcquiaCli.php @@ -108,6 +108,13 @@ public function __construct( The order of the fields is significant. A leading - in the field indicates the field should be sorted in a descending order. Not all fields are sortable.' ), + new InputOption( + 'format', + null, + InputOption::VALUE_REQUIRED, + 'The output format (txt or json)', + 'txt' + ), ] ); diff --git a/src/Commands/AccountCommand.php b/src/Commands/AccountCommand.php index be645d3..64bb300 100644 --- a/src/Commands/AccountCommand.php +++ b/src/Commands/AccountCommand.php @@ -20,14 +20,17 @@ class AccountCommand extends AcquiaCommand */ public function account(Config $config, Account $accountAdapter) { + $account = $accountAdapter->get(); + + if ($this->input()->getOption('format') === 'json') { + return $this->writeln(json_encode($account)); + } $extraConfig = $config->get('extraconfig'); $tz = $extraConfig['timezone']; $format = $extraConfig['format']; $timezone = new \DateTimeZone($tz); - $account = $accountAdapter->get(); - $lastLogin = new \DateTime($account->last_login_at); $lastLogin->setTimezone($timezone); $createdAt = new \DateTime($account->created_at); diff --git a/src/Commands/DomainCommand.php b/src/Commands/DomainCommand.php index e5de0d8..103ffaf 100644 --- a/src/Commands/DomainCommand.php +++ b/src/Commands/DomainCommand.php @@ -27,6 +27,9 @@ public function domainList(OutputInterface $output, Domains $domainAdapter, $uui { $environment = $this->cloudapiService->getEnvironment($uuid, $environment); $domains = $domainAdapter->getAll($environment->uuid); + if ($this->input()->getOption('format') === 'json') { + return $this->writeln(json_encode($domains)); + } $table = new Table($output); $table->setHeaders(['Hostname', 'Default', 'Active', 'Uptime']); @@ -68,6 +71,10 @@ public function domainInfo(OutputInterface $output, Domains $domainAdapter, $uui $environment = $this->cloudapiService->getEnvironment($uuid, $environment); $domain = $domainAdapter->status($environment->uuid, $domain); + if ($this->input()->getOption('format') === 'json') { + return $this->writeln(json_encode($domain)); + } + $table = new Table($output); $table->setHeaders(['Hostname', 'Active', 'DNS Resolves', 'IP Addresses', 'CNAMES']); $table->setColumnStyle(1, 'center-align');