Skip to content

Commit

Permalink
[chain] Improve placeholder default values management. (#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmolivas committed Dec 9, 2016
1 parent eec3f76 commit 56a5cdf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
18 changes: 18 additions & 0 deletions config/dist/chain/site.new.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# How to use
# site:new --placeholder="directory:/path/to/drupal-project/" --placeholder="profile:minimal"
command:
name: site:new
description: 'Create, install and launch a new Drupal project'
commands:
# Create Drupal project using DrupalComposer
- command: exec
arguments:
bin: composer create-project %{{repository|drupal-composer/drupal-project:8.x-dev}} %{{directory}} --prefer-dist --no-progress --no-interaction
# Install Drupal
- command: exec
arguments:
bin: drupal site:install %{{profile|standard}} --root=%{{directory}} --no-interaction
# Start PHP bult-in server
- command: exec
arguments:
bin: drupal server --root=%{{directory}}
11 changes: 7 additions & 4 deletions src/Command/Chain/ChainCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ protected function interact(InputInterface $input, OutputInterface $output)
$chainContent = $this->getFileContents($file);

$placeholder = $input->getOption('placeholder');

$inlinePlaceHolders = $this->extractInlinePlaceHolders($chainContent);

if (!$placeholder && $inlinePlaceHolders) {
Expand Down Expand Up @@ -140,15 +141,13 @@ protected function execute(InputInterface $input, OutputInterface $output)
$learning = $input->hasOption('learning')?$input->getOption('learning'):false;

$file = $input->getOption('file');

if (!$file) {
$io->error($this->trans('commands.chain.messages.missing_file'));

return 1;
}

$fileSystem = new Filesystem();

$file = calculateRealPath($file);

if (!$fileSystem->exists($file)) {
Expand All @@ -166,6 +165,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
if ($placeholder) {
$placeholder = $this->inlineValueAsArray($placeholder);
}
$placeHolderOptions = [];
foreach ($placeholder as $placeholderItem) {
$placeHolderOptions[] = key($placeholderItem);
}

$chainContent = $this->getFileContents($file);
$inlinePlaceHolders = $this->extractInlinePlaceHolders($chainContent);
Expand All @@ -184,11 +187,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
continue;
}

if ($placeholder && array_key_exists($inlinePlaceHolder, $placeholder[0])) {
if (in_array($inlinePlaceHolder, $placeHolderOptions)) {
continue;
}

$placeholder[0][$inlinePlaceHolder] = $inlinePlaceHolderDefault;
$placeholder[] = [$inlinePlaceHolder => $inlinePlaceHolderDefault];
}
}

Expand Down

0 comments on commit 56a5cdf

Please sign in to comment.