Skip to content

Commit 94c13ac

Browse files
committed
Add options for renaming parameters in IncenteevParameterHandler
1 parent 8e559af commit 94c13ac

3 files changed

Lines changed: 55 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.0.1
2+
3+
* Add a rename map used to rename parameters when updating the parameters file
4+
15
## 2.0.0 (2013-04-06)
26

37
* BC BREAK the env map has been changed, inverting the keys and the values. Refs #14

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,33 @@ As environment variables can only be strings, they are also parsed as inline
105105
Yaml values to allows specifying ``null``, ``false``, ``true`` or numbers
106106
easily.
107107

108+
## Renaming parameters
109+
110+
If you are renaming a parameter, the new key will be set according to the usual
111+
routine (prompt if possible, use environment variables, use default).
112+
To have the parameters handler use the value of an (obsolete) parameter, specify
113+
a rename-map:
114+
```json
115+
{
116+
"extra": {
117+
"incenteev-parameters": {
118+
"rename-map": {
119+
"new_param_1": "old_param_1",
120+
"new_param_2": "old_param_2"
121+
}
122+
}
123+
}
124+
}
125+
```
126+
127+
This will create the new parameters new_param_1 and new_param_2 while using the
128+
values from old_param_1 and old_param_2, respectively. It will not remove the
129+
old parameters unless you've also removed them from the dist version.
130+
131+
If the old parameter is no longer present (maybe because it has been renamed and
132+
remove already), no parameters are overwritten. You don't need to remove obsolete
133+
parameters from the rename map once they have been renamed.
134+
108135
Warning: This parameters handler will overwrite any comments or spaces into
109136
your parameters.yml file so handle with care. So if you want to give format
110137
and comments to your parameter's file you should do it on your dist version.

ScriptHandler.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ public static function buildParameters(Event $event)
6767
}
6868
$actualParams = (array) $actualValues[$parameterKey];
6969

70+
// Grab values for parameters that were renamed
71+
$renameMap = empty($extras['incenteev-parameters']['rename-map']) ? array() : (array) $extras['incenteev-parameters']['rename-map'];
72+
$actualParams = array_replace($actualParams, self::getRenameValues($renameMap, $actualParams));
73+
7074
if (!$keepOutdatedParams) {
7175
// Remove the outdated params
7276
foreach ($actualParams as $key => $value) {
@@ -99,6 +103,26 @@ private static function getEnvValues(array $envMap)
99103
return $params;
100104
}
101105

106+
private static function getRenameValues(array $renameMap, $actualParams)
107+
{
108+
$params = array();
109+
foreach ($renameMap as $param => $oldParam) {
110+
if (array_key_exists($param, $actualParams)) {
111+
continue;
112+
}
113+
114+
if (!array_key_exists($oldParam, $actualParams)) {
115+
continue;
116+
}
117+
118+
if ($actualParams[$oldParam]) {
119+
$params[$param] = $actualParams[$oldParam];
120+
}
121+
}
122+
123+
return $params;
124+
}
125+
102126
private static function getParams(IOInterface $io, array $expectedParams, array $actualParams)
103127
{
104128
// Simply use the expectedParams value as default for the missing params.

0 commit comments

Comments
 (0)