Skip to content

Commit

Permalink
[chain] Allow placeholders to support array value as default. (#181)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmolivas committed Jun 30, 2017
1 parent b1f3680 commit 1030e98
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 13 deletions.
7 changes: 5 additions & 2 deletions config/dist/chain/site-new.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ command:
name: site:new
description: 'Download a new Drupal project'
vars:
repository: drupal-composer/drupal-project:8.x-dev
repository:
- drupal-composer/drupal-project:8.x-dev
- acquia/lightning-project
- acquia/reservoir-project
commands:
# Create Drupal project using DrupalComposer
# Create Drupal project using Composer
- command: exec
arguments:
bin: composer create-project %{{repository}} %{{directory}} --prefer-dist --no-progress --no-interaction
43 changes: 32 additions & 11 deletions src/Command/Chain/ChainCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,32 @@ function($value) {

if ($missingInlinePlaceHolders) {
foreach ($inlinePlaceHolders as $inlinePlaceHolder => $inlinePlaceHolderValue) {
$placeholder[] = sprintf(
'%s:%s',
$inlinePlaceHolder,
$io->ask(
sprintf(
'Enter value for %s placeholder',
$inlinePlaceHolder
),
$inlinePlaceHolderValue
)
);
if (is_array($inlinePlaceHolderValue)) {
$placeholder[] = sprintf(
'%s:%s',
$inlinePlaceHolder,
$io->choice(
sprintf(
'Select value for %s placeholder',
$inlinePlaceHolder
),
$inlinePlaceHolderValue,
current($inlinePlaceHolderValue)
)
);
} else {
$placeholder[] = sprintf(
'%s:%s',
$inlinePlaceHolder,
$io->ask(
sprintf(
'Enter value for %s placeholder',
$inlinePlaceHolder
),
$inlinePlaceHolderValue
)
);
}
}
$input->setOption('placeholder', $placeholder);
}
Expand Down Expand Up @@ -181,6 +196,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
$chainContent = $this->chainDiscovery->getFileContents($file);
$inlinePlaceHolders = $this->chainDiscovery->extractInlinePlaceHolders($chainContent);

foreach ($inlinePlaceHolders as $inlinePlaceHolder => $inlinePlaceHolderValue) {
if (is_array($inlinePlaceHolderValue)) {
$inlinePlaceHolders[$inlinePlaceHolder] = current($inlinePlaceHolderValue);
}
}

$placeholder = $input->getOption('placeholder');
if ($placeholder) {
$placeholder = $this->placeHolderInlineValueAsArray($placeholder);
Expand Down

0 comments on commit 1030e98

Please sign in to comment.