Skip to content

Commit

Permalink
Adds the option to throw an exception on missing parameters in non-in…
Browse files Browse the repository at this point in the history
…teractive mode Incenteev#105
  • Loading branch information
Silvan Thus committed Jan 18, 2017
1 parent d7ce7f0 commit 2ab23ea
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
16 changes: 13 additions & 3 deletions Processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ private function processParams(array $config, array $expectedParams, array $actu
// Add the params coming from the environment values
$actualParams = array_replace($actualParams, $this->getEnvValues($envMap));

return $this->getParams($expectedParams, $actualParams);
return $this->getParams($config, $expectedParams, $actualParams);
}

private function getEnvValues(array $envMap)
Expand Down Expand Up @@ -137,10 +137,20 @@ private function processRenamedValues(array $renameMap, array $actualParams)
return $actualParams;
}

private function getParams(array $expectedParams, array $actualParams)
private function getParams(array $config, array $expectedParams, array $actualParams)
{
// Simply use the expectedParams value as default for the missing params.
if (!$this->io->isInteractive()) {
if (isset($config['exception-when-missing'])) {
foreach ($expectedParams as $key => $message) {
if (array_key_exists($key, $actualParams)) {
continue;
}

throw new \InvalidArgumentException(sprintf('Some parameters are missing. Please provide them. Missing %s', $key));
}
}

// Simply use the expectedParams value as default for the missing params.
return array_replace($expectedParams, $actualParams);
}

Expand Down
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,18 @@ in the parameters file, using the value of the dist file as default value.
All prompted values are parsed as inline Yaml, to allow you to define ``true``,
``false``, ``null`` or numbers easily.
If composer is run in a non-interactive mode, the values of the dist file
will be used for missing parameters.
will be used for missing parameters, unless the ``exception-when-missing`` is set
in the configuration, then an exception is thrown. Example:

```json
{
"extra": {
"incenteev-parameters": {
"exception-when-missing": true
}
}
}
```

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

0 comments on commit 2ab23ea

Please sign in to comment.