Skip to content

Commit dda5fa7

Browse files
committed
Improve setting an organization address
1 parent d0fbb43 commit dda5fa7

File tree

5 files changed

+294
-11
lines changed

5 files changed

+294
-11
lines changed

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"doctrine/cache": "~1.5",
88
"guzzlehttp/guzzle": "^5.3",
99
"guzzlehttp/ringphp": "^1.1",
10-
"platformsh/console-form": ">=0.0.25 <2.0",
10+
"platformsh/console-form": ">=0.0.26 <2.0",
1111
"platformsh/client": ">=0.57.0 <2.0",
1212
"symfony/console": "^3.0 >=3.2",
1313
"symfony/yaml": "^3.0 || ^2.6",
@@ -20,7 +20,8 @@
2020
"symfony/dependency-injection": "^3.1",
2121
"symfony/config": "^3.1",
2222
"paragonie/random_compat": "^2.0",
23-
"ext-json": "*"
23+
"ext-json": "*",
24+
"commerceguys/addressing": "^1.0"
2425
},
2526
"suggest": {
2627
"drush/drush": "For Drupal projects"

composer.lock

Lines changed: 139 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Command/Organization/Billing/OrganizationAddressCommand.php

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
use Platformsh\Cli\Service\Table;
99
use Platformsh\Client\Model\Organization\Address;
1010
use Platformsh\Client\Model\Organization\Organization;
11+
use Platformsh\ConsoleForm\Form;
1112
use Symfony\Component\Console\Exception\InvalidArgumentException;
1213
use Symfony\Component\Console\Input\InputArgument;
1314
use Symfony\Component\Console\Input\InputInterface;
15+
use Symfony\Component\Console\Input\InputOption;
1416
use Symfony\Component\Console\Output\OutputInterface;
1517

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

3134
protected function execute(InputInterface $input, OutputInterface $output)
3235
{
36+
if ($input->getOption('form') && !$input->isInteractive()) {
37+
$this->stdErr->writeln('The --form option cannot be used non-interactively.');
38+
return 1;
39+
}
40+
3341
$property = $input->getArgument('property');
3442
$updates = $this->parseUpdates($input);
3543

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

48+
if ($input->getOption('form')) {
49+
$form = Form::fromArray($this->getAddressFormFields());
50+
if (($address->country !== '') && ($field = $form->getField('country'))) {
51+
$field->set('default', $address->country);
52+
}
53+
foreach ($address->getProperties() as $key => $value) {
54+
if ($value !== '' && ($field = $form->getField($key))) {
55+
$field->set('autoCompleterValues', [$value]);
56+
}
57+
}
58+
foreach ($updates as $key => $value) {
59+
if ($field = $form->getField($key)) {
60+
$field->set('default', $value);
61+
}
62+
}
63+
/** @var \Platformsh\Cli\Service\QuestionHelper $questionHelper */
64+
$questionHelper = $this->getService('question_helper');
65+
$updates = $form->resolveOptions($input, $output, $questionHelper);
66+
}
67+
4068
/** @var PropertyFormatter $formatter */
4169
$formatter = $this->getService('property_formatter');
4270

4371
$result = 0;
44-
if ($property !== null) {
72+
if ($property !== null || !empty($updates)) {
4573
if (empty($updates)) {
4674
$formatter->displayData($output, $address->getProperties(), $property);
4775
return $result;
@@ -76,6 +104,7 @@ protected function display(Address $address, Organization $org, InputInterface $
76104
$table->renderSimple($values, $headings);
77105

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

0 commit comments

Comments
 (0)