88use Platformsh \Cli \Service \Table ;
99use Platformsh \Client \Model \Organization \Address ;
1010use Platformsh \Client \Model \Organization \Organization ;
11+ use Platformsh \ConsoleForm \Form ;
1112use Symfony \Component \Console \Exception \InvalidArgumentException ;
1213use Symfony \Component \Console \Input \InputArgument ;
1314use Symfony \Component \Console \Input \InputInterface ;
15+ use Symfony \Component \Console \Input \InputOption ;
1416use Symfony \Component \Console \Output \OutputInterface ;
1517
1618class 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