Skip to content

Commit

Permalink
Improve setting an organization address
Browse files Browse the repository at this point in the history
  • Loading branch information
pjcdawkins committed Jan 14, 2022
1 parent d0fbb43 commit df29403
Show file tree
Hide file tree
Showing 5 changed files with 291 additions and 11 deletions.
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.

30 changes: 28 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,48 @@ 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());
foreach ($address->getProperties() as $key => $value) {
if ($value !== '' && ($field = $form->getField($key))) {
$field->set('default', $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 +101,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

0 comments on commit df29403

Please sign in to comment.