8
8
use Platformsh \Cli \Service \Table ;
9
9
use Platformsh \Client \Model \Organization \Address ;
10
10
use Platformsh \Client \Model \Organization \Organization ;
11
+ use Platformsh \ConsoleForm \Form ;
11
12
use Symfony \Component \Console \Exception \InvalidArgumentException ;
12
13
use Symfony \Component \Console \Input \InputArgument ;
13
14
use Symfony \Component \Console \Input \InputInterface ;
15
+ use Symfony \Component \Console \Input \InputOption ;
14
16
use Symfony \Component \Console \Output \OutputInterface ;
15
17
16
18
class OrganizationAddressCommand extends OrganizationCommandBase
@@ -23,25 +25,51 @@ protected function configure()
23
25
->addOrganizationOptions ()
24
26
->addArgument ('property ' , InputArgument::OPTIONAL , 'The name of a property to view or change ' )
25
27
->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 ' );
27
30
PropertyFormatter::configureInput ($ this ->getDefinition ());
28
31
Table::configureInput ($ this ->getDefinition ());
29
32
}
30
33
31
34
protected function execute (InputInterface $ input , OutputInterface $ output )
32
35
{
36
+ if ($ input ->getOption ('form ' ) && !$ input ->isInteractive ()) {
37
+ $ this ->stdErr ->writeln ('The --form option cannot be used non-interactively. ' );
38
+ return 1 ;
39
+ }
40
+
33
41
$ property = $ input ->getArgument ('property ' );
34
42
$ updates = $ this ->parseUpdates ($ input );
35
43
36
44
// The 'orders' link depends on the billing permission.
37
45
$ org = $ this ->validateOrganizationInput ($ input , 'orders ' );
38
46
$ address = $ org ->getAddress ();
39
47
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
+
40
68
/** @var PropertyFormatter $formatter */
41
69
$ formatter = $ this ->getService ('property_formatter ' );
42
70
43
71
$ result = 0 ;
44
- if ($ property !== null ) {
72
+ if ($ property !== null || ! empty ( $ updates ) ) {
45
73
if (empty ($ updates )) {
46
74
$ formatter ->displayData ($ output , $ address ->getProperties (), $ property );
47
75
return $ result ;
@@ -76,6 +104,7 @@ protected function display(Address $address, Organization $org, InputInterface $
76
104
$ table ->renderSimple ($ values , $ headings );
77
105
78
106
if (!$ table ->formatIsMachineReadable ()) {
107
+ $ this ->stdErr ->writeln ('' );
79
108
$ this ->stdErr ->writeln (\sprintf ('To view the billing profile, run: <info>%s</info> ' , $ this ->otherCommandExample ($ input , 'org:billing:profile ' )));
80
109
$ this ->stdErr ->writeln (\sprintf ('To view organization details, run: <info>%s</info> ' , $ this ->otherCommandExample ($ input , 'org:info ' )));
81
110
}
0 commit comments