Skip to content
This repository was archived by the owner on Apr 27, 2026. It is now read-only.

Commit e4571f9

Browse files
committed
Add --app-scope option for variables
1 parent 2303aa0 commit e4571f9

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

src/Command/Variable/VariableCommandBase.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Platformsh\Client\Model\ProjectLevelVariable;
88
use Platformsh\Client\Model\Resource as ApiResource;
99
use Platformsh\Client\Model\Variable as EnvironmentLevelVariable;
10+
use Platformsh\ConsoleForm\Field\ArrayField;
1011
use Platformsh\ConsoleForm\Field\BooleanField;
1112
use Platformsh\ConsoleForm\Field\Field;
1213
use Platformsh\ConsoleForm\Field\OptionsField;
@@ -182,6 +183,33 @@ protected function getFields()
182183
return null;
183184
},
184185
]);
186+
$fields['application_scope'] = new ArrayField('Application scope', [
187+
'optionName' => 'app-scope',
188+
'description' => 'A list of application names to which this variable will apply.',
189+
'questionLine' => 'To which applications should this variable apply?',
190+
'default' => [],
191+
'required' => false,
192+
//q'avoidQuestion' => true,
193+
'validator' => function ($values) {
194+
if ($this->hasSelectedEnvironment()) {
195+
$deployment = $this->api()->getCurrentDeployment($this->getSelectedEnvironment(), false, false);
196+
if (!$deployment) {
197+
return false;
198+
}
199+
$appNames = array_keys($deployment->webapps);
200+
foreach ($values as $value) {
201+
if (!in_array($value, $appNames, true)) {
202+
throw new InvalidArgumentException(sprintf(
203+
'The app "%s" was not found. Valid app names are: %s',
204+
$value,
205+
implode(', ', $appNames)
206+
));
207+
}
208+
}
209+
}
210+
return true;
211+
},
212+
]);
185213
$fields['name'] = new Field('Name', [
186214
'description' => 'The variable name',
187215
'validators' => [

0 commit comments

Comments
 (0)