Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds the option to throw an exception on missing parameters #107

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'])) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should check the value of the config too. Setting it to false should not throw

Copy link
Author

@silvant silvant Jan 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, I chose isset, as that is similar as keep-outdated. Recommend we change both them to !empty && Inline::parse !== false. Do you agree?

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