Skip to content

Commit

Permalink
[chain] Improve chain discovery strategy. (#297)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmolivas committed Jan 30, 2018
1 parent a75d712 commit 3b4d66f
Show file tree
Hide file tree
Showing 15 changed files with 244 additions and 46 deletions.
3 changes: 3 additions & 0 deletions dist/chain/create-data.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
command:
name: create:data
description: 'Create dummy data'
commands:
# Create dummy data
- command: create:users
Expand Down
3 changes: 3 additions & 0 deletions dist/chain/form-sample.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
command:
name: generate:form:example
description: 'Generate form example'
commands:
- command: generate:form:config
options:
Expand Down
3 changes: 3 additions & 0 deletions dist/chain/sample.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
command:
name: generate:example:module
description: 'Generate example module'
commands:
- command: generate:module
options:
Expand Down
15 changes: 9 additions & 6 deletions dist/chain/site-install-placeholers-env.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
command:
name: site:install:env
description: 'Install site using environment placeholders'
commands:
# Install Drupal
- command: site:install
options:
langcode: en
db-type: '%env(DATABASE_TYPE)%'
db-host: '%env(DATABASE_HOST)%'
db-name: '%env(DATABASE_NAME)%'
db-user: '%env(DATABASE_USER)%'
db-pass: '%env(DATABASE_PASSWORD)%'
db-port: '%env(DATABASE_PORT)%'
db-type: '{{ env("DATABASE_TYPE") }}'
db-host: '{{ env("DATABASE_HOST") }}'
db-name: '{{ env("DATABASE_NAME") }}'
db-user: '{{ env("DATABASE_USER") }}'
db-pass: '{{ env("DATABASE_PASSWORD") }}'
db-port: '{{ env("DATABASE_PORT") }}'
site-name: 'Drupal 8 site'
site-mail: admin@example.org # default email
account-name: admin # default account
Expand Down
3 changes: 3 additions & 0 deletions dist/chain/site-install-placeholers.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
command:
name: site:install:inline
description: 'Install site using inline placeholders'
vars:
db_type: mysql
db_host: 127.0.0.1
Expand Down
3 changes: 3 additions & 0 deletions dist/chain/site-install.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
command:
name: site:install:sqlite
description: 'Install site using sqlite'
commands:
# Install Drupal
- command: site:install
Expand Down
5 changes: 5 additions & 0 deletions dist/chain/site-update.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
command:
name: site:update
description: 'Execute update commands'
commands:
# Backup current database
- command: database:dump
Expand All @@ -9,6 +12,8 @@ commands:
- command: update:execute
arguments:
module: 'all'
# Run pending update entities
- command: update:entities
# Rebuild caches
- command: cache:rebuild
arguments:
Expand Down
2 changes: 1 addition & 1 deletion services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ services:
class: Drupal\Console\Core\Utils\StringConverter
console.chain_discovery:
class: Drupal\Console\Core\Utils\ChainDiscovery
arguments: ['@console.root', '@console.configuration_manager']
arguments: ['@console.root', '@console.configuration_manager', '@console.message_manager', '@console.translator_manager']
console.count_code_lines:
class: Drupal\Console\Core\Utils\CountCodeLines
console.message_manager:
Expand Down
2 changes: 1 addition & 1 deletion src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ public function doRun(InputInterface $input, OutputInterface $output)
$input,
$output
);

if ($this->showMessages($input)) {
$messages = $messageManager->getMessages();

Expand All @@ -209,6 +208,7 @@ public function doRun(InputInterface $input, OutputInterface $output)
}
}


return $code;
}

Expand Down
5 changes: 3 additions & 2 deletions src/Command/Chain/BaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public function __construct(
) {
$this->chainDiscovery = $chainDiscovery;
parent::__construct();
$this->ignoreValidationErrors();
}

protected function initialize(
Expand Down Expand Up @@ -93,11 +94,11 @@ protected function getFileOption()
$file = $input->getOption('file');

if (!$file) {
$files = $this->chainDiscovery->getChainFiles(true);
$files = array_keys($this->chainDiscovery->getFiles());

$file = $this->getIo()->choice(
$this->trans('commands.chain.questions.chain-file'),
array_values($files)
$files
);
}

Expand Down
11 changes: 11 additions & 0 deletions src/Command/Chain/ChainCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,17 @@ protected function interact(InputInterface $input, OutputInterface $output)
$inlinePlaceHolderValue
);
}

if (!$input->hasOption($inlinePlaceHolder)) {
$this->addOption(
$inlinePlaceHolder,
null,
InputOption::VALUE_OPTIONAL,
null,
null
);
}

$input->setOption($inlinePlaceHolder, $placeHolderValue);
}
}
Expand Down
17 changes: 11 additions & 6 deletions src/Command/Debug/ChainCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,24 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$files = $this->chainDiscovery->getChainFiles();
$files = $this->chainDiscovery->getFiles();
$filesPerDirectory = $this->chainDiscovery->getFilesPerDirectory();

foreach ($files as $directory => $chainFiles) {
$this->getIo()->info($this->trans('commands.debug.chain.messages.directory'), false);
foreach ($filesPerDirectory as $directory => $fileNames) {
$this->getIo()->info(' ' . $this->trans('commands.debug.chain.messages.directory'), false);
$this->getIo()->comment($directory);

$tableHeader = [
$this->trans('commands.debug.chain.messages.file')
$this->trans('commands.debug.chain.messages.file'),
$this->trans('commands.debug.chain.messages.command')
];

$tableRows = [];
foreach ($chainFiles as $file) {
$tableRows[] = $file;
foreach ($fileNames as $file) {
$tableRows[] = [
'file' => $file,
'command' => $files[$directory.$file]['command']
];
}

$this->getIo()->table($tableHeader, $tableRows);
Expand Down
2 changes: 2 additions & 0 deletions src/Command/ListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
'command' => $this->getApplication()->find($commandName)
]
);

$this->getIo()->newLine();
}

/**
Expand Down
Loading

0 comments on commit 3b4d66f

Please sign in to comment.