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
Override couscous.yml configuration from command line #187
Changes from 4 commits
55e25fb
d1a2106
f1a8565
520bb20
fa01d5c
6e1a019
f6527b0
8b3e1a4
fb947a2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,6 +82,13 @@ protected function configure() | |
null, | ||
InputOption::VALUE_REQUIRED, | ||
'Target branch in which to deploy the website.' | ||
) | ||
->addOption( | ||
'config', | ||
null, | ||
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, | ||
'If specified will override entries in couscous.yaml (key=value)', | ||
[] | ||
); | ||
} | ||
|
||
|
@@ -93,9 +100,12 @@ protected function execute(InputInterface $input, OutputInterface $output) | |
$sourceDirectory = $input->getArgument('source'); | ||
$repositoryUrl = $input->getOption('repository'); | ||
$targetBranch = $input->getOption('branch'); | ||
$tempConfigRaw = $input->getOption('config'); | ||
|
||
$project = new Project($sourceDirectory, getcwd().'/.couscous/generated'); | ||
|
||
$project->metadata['tempConfigRaw'] = $tempConfigRaw; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
// Generate the website | ||
$this->generator->generate($project, $output); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
namespace Couscous\Module\Config\Step; | ||
|
||
use Couscous\Model\Project; | ||
use Psr\Log\LoggerInterface; | ||
|
||
/** | ||
* Override config variables when specified using --config option. | ||
* | ||
* @author D.J. Marcolesco <dj.marcolesco@gmail.com> | ||
*/ | ||
class OverrideConfigFromCLI implements \Couscous\Step | ||
{ | ||
/** | ||
* @var LoggerInterface | ||
*/ | ||
private $logger; | ||
|
||
public function __construct(LoggerInterface $logger) | ||
{ | ||
$this->logger = $logger; | ||
} | ||
|
||
public function __invoke(Project $project) | ||
{ | ||
if ($project->metadata['tempConfigRaw']) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor detail but you can return early to avoid 1 level of indentation There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good tip! |
||
$keys = $values = []; | ||
foreach ($project->metadata['tempConfigRaw'] as $item) { | ||
$explosion = explode('=', $item, 2); | ||
$this->logger->notice('Overriding global config: '.$explosion[0].' = "'.$explosion[1].'"'); | ||
|
||
$keys[] = $explosion[0]; | ||
$values[] = $explosion[1]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of using 2 arrays wouldn't it be possible to use one and do: $config[$explosion[0]] = $explosion[1]; ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it would! I'm just a silly. :) |
||
} | ||
|
||
unset($project->metadata['tempConfigRaw']); | ||
|
||
$project->metadata->setMany(array_combine($keys, $values)); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo:
couscous.yaml
->couscous.yml