Skip to content

Commit 2ab23ea

Browse files
author
Silvan Thus
committed
Adds the option to throw an exception on missing parameters in non-interactive mode #105
1 parent d7ce7f0 commit 2ab23ea

2 files changed

Lines changed: 25 additions & 4 deletions

File tree

Processor.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ private function processParams(array $config, array $expectedParams, array $actu
104104
// Add the params coming from the environment values
105105
$actualParams = array_replace($actualParams, $this->getEnvValues($envMap));
106106

107-
return $this->getParams($expectedParams, $actualParams);
107+
return $this->getParams($config, $expectedParams, $actualParams);
108108
}
109109

110110
private function getEnvValues(array $envMap)
@@ -137,10 +137,20 @@ private function processRenamedValues(array $renameMap, array $actualParams)
137137
return $actualParams;
138138
}
139139

140-
private function getParams(array $expectedParams, array $actualParams)
140+
private function getParams(array $config, array $expectedParams, array $actualParams)
141141
{
142-
// Simply use the expectedParams value as default for the missing params.
143142
if (!$this->io->isInteractive()) {
143+
if (isset($config['exception-when-missing'])) {
144+
foreach ($expectedParams as $key => $message) {
145+
if (array_key_exists($key, $actualParams)) {
146+
continue;
147+
}
148+
149+
throw new \InvalidArgumentException(sprintf('Some parameters are missing. Please provide them. Missing %s', $key));
150+
}
151+
}
152+
153+
// Simply use the expectedParams value as default for the missing params.
144154
return array_replace($expectedParams, $actualParams);
145155
}
146156

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,18 @@ in the parameters file, using the value of the dist file as default value.
6060
All prompted values are parsed as inline Yaml, to allow you to define ``true``,
6161
``false``, ``null`` or numbers easily.
6262
If composer is run in a non-interactive mode, the values of the dist file
63-
will be used for missing parameters.
63+
will be used for missing parameters, unless the ``exception-when-missing`` is set
64+
in the configuration, then an exception is thrown. Example:
65+
66+
```json
67+
{
68+
"extra": {
69+
"incenteev-parameters": {
70+
"exception-when-missing": true
71+
}
72+
}
73+
}
74+
```
6475

6576
**Warning:** This parameters handler will overwrite any comments or spaces into
6677
your parameters.yml file so handle with care. If you want to give format

0 commit comments

Comments
 (0)