Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"doctrine/cache": "~1.5",
"guzzlehttp/guzzle": "^5.3",
"guzzlehttp/ringphp": "^1.1",
"platformsh/console-form": ">=0.0.25 <2.0",
"platformsh/console-form": ">=0.0.26 <2.0",
"platformsh/client": ">=0.57.0 <2.0",
"symfony/console": "^3.0 >=3.2",
"symfony/yaml": "^3.0 || ^2.6",
Expand All @@ -20,7 +20,8 @@
"symfony/dependency-injection": "^3.1",
"symfony/config": "^3.1",
"paragonie/random_compat": "^2.0",
"ext-json": "*"
"ext-json": "*",
"commerceguys/addressing": "^1.0"
},
"suggest": {
"drush/drush": "For Drupal projects"
Expand Down
146 changes: 139 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 31 additions & 2 deletions src/Command/Organization/Billing/OrganizationAddressCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
use Platformsh\Cli\Service\Table;
use Platformsh\Client\Model\Organization\Address;
use Platformsh\Client\Model\Organization\Organization;
use Platformsh\ConsoleForm\Form;
use Symfony\Component\Console\Exception\InvalidArgumentException;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class OrganizationAddressCommand extends OrganizationCommandBase
Expand All @@ -23,25 +25,51 @@ protected function configure()
->addOrganizationOptions()
->addArgument('property', InputArgument::OPTIONAL, 'The name of a property to view or change')
->addArgument('value', InputArgument::OPTIONAL, 'A new value for the property')
->addArgument('properties', InputArgument::IS_ARRAY|InputArgument::OPTIONAL, 'Additional property/value pairs');
->addArgument('properties', InputArgument::IS_ARRAY|InputArgument::OPTIONAL, 'Additional property/value pairs')
->addOption('form', null, InputOption::VALUE_NONE, 'Display a form for updating the address interactively');
PropertyFormatter::configureInput($this->getDefinition());
Table::configureInput($this->getDefinition());
}

protected function execute(InputInterface $input, OutputInterface $output)
{
if ($input->getOption('form') && !$input->isInteractive()) {
$this->stdErr->writeln('The --form option cannot be used non-interactively.');
return 1;
}

$property = $input->getArgument('property');
$updates = $this->parseUpdates($input);

// The 'orders' link depends on the billing permission.
$org = $this->validateOrganizationInput($input, 'orders');
$address = $org->getAddress();

if ($input->getOption('form')) {
$form = Form::fromArray($this->getAddressFormFields());
if (($address->country !== '') && ($field = $form->getField('country'))) {
$field->set('default', $address->country);
}
foreach ($address->getProperties() as $key => $value) {
if ($value !== '' && $key !== 'country' && ($field = $form->getField($key))) {
$field->set('autoCompleterValues', [$value]);
}
}
foreach ($updates as $key => $value) {
if ($field = $form->getField($key)) {
$field->set('default', $value);
}
}
/** @var \Platformsh\Cli\Service\QuestionHelper $questionHelper */
$questionHelper = $this->getService('question_helper');
$updates = $form->resolveOptions($input, $output, $questionHelper);
}

/** @var PropertyFormatter $formatter */
$formatter = $this->getService('property_formatter');

$result = 0;
if ($property !== null) {
if ($property !== null || !empty($updates)) {
if (empty($updates)) {
$formatter->displayData($output, $address->getProperties(), $property);
return $result;
Expand Down Expand Up @@ -76,6 +104,7 @@ protected function display(Address $address, Organization $org, InputInterface $
$table->renderSimple($values, $headings);

if (!$table->formatIsMachineReadable()) {
$this->stdErr->writeln('');
$this->stdErr->writeln(\sprintf('To view the billing profile, run: <info>%s</info>', $this->otherCommandExample($input, 'org:billing:profile')));
$this->stdErr->writeln(\sprintf('To view organization details, run: <info>%s</info>', $this->otherCommandExample($input, 'org:info')));
}
Expand Down
Loading