Skip to content

Commit

Permalink
Add an option to process settings .csv even if environment does not e…
Browse files Browse the repository at this point in the history
…xist (fallback to default)
  • Loading branch information
steverobbins committed Aug 30, 2016
1 parent 71a0eb8 commit 715dd76
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
9 changes: 8 additions & 1 deletion src/Zettr/Command/ApplyCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ protected function configure()
InputOption::VALUE_NONE,
'Dry run'
)
->addOption(
'skipEnvMissingError',
null,
InputOption::VALUE_NONE,
'Continue if specified env is not found'
)
->addOption(
'groups',
null,
Expand Down Expand Up @@ -59,7 +65,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
$environment,
$file,
$input->getOption('groups'),
$input->getOption('excludeGroups')
$input->getOption('excludeGroups'),
$input->getOption('skipEnvMissingError')
);
$processor->setOutput($output);
try {
Expand Down
11 changes: 6 additions & 5 deletions src/Zettr/HandlerCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class HandlerCollection implements \Iterator {
* @param array $excludeGroups
* @throws \Exception
*/
public function buildFromSettingsCSVFile($csvFile, $environment, $defaultEnvironment='DEFAULT', array $includeGroups=array(), array $excludeGroups=array()) {
public function buildFromSettingsCSVFile($csvFile, $environment, $defaultEnvironment='DEFAULT', array $includeGroups=array(), array $excludeGroups=array(), $skipEnvMissingError=false) {
if (!is_file($csvFile)) {
throw new \Exception('File "'.$csvFile.'" not found.');
}
Expand Down Expand Up @@ -124,7 +124,8 @@ public function buildFromSettingsCSVFile($csvFile, $environment, $defaultEnviron
$row,
$environment,
$defaultEnvironment,
$handler
$handler,
$skipEnvMissingError
);
if (strtolower(trim($value)) == '--empty--') {
$value = '';
Expand Down Expand Up @@ -191,11 +192,11 @@ protected function getColumnIndexForEnvironment($environment, $checkOnly=false)
* @throws \Exception
* @return string
*/
private function getValueFromRow(array $row, $environment, $fallbackEnvironment, Handler\AbstractHandler $handler=null) {
private function getValueFromRow(array $row, $environment, $fallbackEnvironment, Handler\AbstractHandler $handler=null, $skipEnvMissingError=false) {
$value = null;
$defaultColumnIndex = $this->getColumnIndexForEnvironment($fallbackEnvironment, true);
$envColumnIndex = $this->getColumnIndexForEnvironment($environment);
if (array_key_exists($envColumnIndex, $row)) {
$envColumnIndex = $this->getColumnIndexForEnvironment($environment, $skipEnvMissingError);
if ($envColumnIndex !== false && array_key_exists($envColumnIndex, $row)) {
$value = $row[$envColumnIndex];
if ($value == '--empty--') {
$value = '';
Expand Down
5 changes: 3 additions & 2 deletions src/Zettr/Processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Processor {
* @param array $excludeGroups
* @throws \InvalidArgumentException
*/
public function __construct($environment, $settingsFilePath, $groups=null, $excludeGroups=null) {
public function __construct($environment, $settingsFilePath, $groups=null, $excludeGroups=null, $skipEnvMissingError=false) {
if (empty($environment)) {
throw new \InvalidArgumentException('No environment parameter set.');
}
Expand All @@ -73,7 +73,8 @@ public function __construct($environment, $settingsFilePath, $groups=null, $excl
$this->environment,
'DEFAULT',
$this->groups,
$this->excludeGroups
$this->excludeGroups,
$skipEnvMissingError
);
}

Expand Down
Binary file modified zettr.phar
Binary file not shown.

0 comments on commit 715dd76

Please sign in to comment.