Skip to content

Commit

Permalink
[generate:site:alias] Add new command. (#282)
Browse files Browse the repository at this point in the history
* [generate:site:alias] Add new command.

* [generate:site:alias] Improve code.
  • Loading branch information
jmolivas committed Jan 18, 2018
1 parent 0c4e7f6 commit 54b28d8
Show file tree
Hide file tree
Showing 11 changed files with 484 additions and 42 deletions.
19 changes: 15 additions & 4 deletions services.yml
Expand Up @@ -31,6 +31,8 @@ services:
class: Drupal\Console\Core\Utils\CountCodeLines
console.message_manager:
class: Drupal\Console\Core\Utils\MessageManager
console.drupal_finder:
class: Drupal\Console\Core\Utils\DrupalFinder
# DrupalConsoleCore Commands
console.about:
class: Drupal\Console\Core\Command\AboutCommand
Expand Down Expand Up @@ -88,13 +90,22 @@ services:
arguments: ['@console.configuration_manager']
tags:
- { name: drupal.command }
console.drush:
class: Drupal\Console\Core\Command\DrushCommand
arguments: ['@console.configuration_manager', '@console.chain_queue']
tags:
- { name: drupal.command }
console.generate_site_alias:
class: Drupal\Console\Core\Command\Generate\SiteAliasCommand
arguments: ['@console.site_alias_generator', '@console.configuration_manager', '@console.drupal_finder']
tags:
- { name: drupal.command }
# DrupalConsoleCore Generators
console.init_generator:
class: Drupal\Console\Core\Generator\InitGenerator
tags:
- { name: drupal.generator }
console.drush:
class: Drupal\Console\Core\Command\DrushCommand
arguments: ['@console.configuration_manager', '@console.chain_queue']
console.site_alias_generator:
class: Drupal\Console\Core\Generator\SiteAliasGenerator
tags:
- { name: drupal.command }
- { name: drupal.generator }
10 changes: 8 additions & 2 deletions src/Application.php
Expand Up @@ -175,8 +175,8 @@ public function doRun(InputInterface $input, OutputInterface $output)
if (in_array($this->commandName, $namespaces)) {
$input = new ArrayInput(
[
'command' => 'list',
'namespace' => $this->commandName
'command' => 'list',
'namespace' => $this->commandName
]
);
$this->commandName = 'list';
Expand Down Expand Up @@ -480,6 +480,12 @@ private function registerGenerators()
$this->container->get('console.count_code_lines')
);
}

if (method_exists($generator, 'setDrupalFinder')) {
$generator->setDrupalFinder(
$this->container->get('console.drupal_finder')
);
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/Command/Chain/ChainCommand.php
Expand Up @@ -212,11 +212,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

$parser = new Parser();
$configData = $parser->parse($chainContent);
$chainData = $parser->parse($chainContent);

$commands = [];
if (array_key_exists('commands', $configData)) {
$commands = $configData['commands'];
if (array_key_exists('commands', $chainData)) {
$commands = $chainData['commands'];
}

$chainInlineOptions = $input->getOptions();
Expand Down
25 changes: 16 additions & 9 deletions src/Command/Debug/SiteCommand.php
Expand Up @@ -70,23 +70,30 @@ protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);

$sites = array_keys($this->configurationManager->getSites());
$sites = $this->configurationManager->getSites();

if (!$sites) {
$io->error($this->trans('commands.debug.site.messages.invalid-sites'));

return 1;
}


// --target argument
$target = $input->getArgument('target');
if (!$target) {
$tableHeader =[
$this->trans('commands.debug.site.messages.site'),
];

$io->table($tableHeader, $sites);
foreach ($sites as $key => $site) {
$environments = array_keys($site);
unset($environments[0]);

$environments = array_map(
function ($element) use ($key) {
return $key . '.' . $element;
},
$environments
);

$io->info($key);
$io->listing($environments);
}

return 0;
}
Expand Down Expand Up @@ -114,7 +121,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

$io->info($target);
$dumper = new Dumper();
$io->writeln($dumper->dump($targetConfig, 2));
$io->writeln($dumper->dump($targetConfig, 4, 2));

return 0;
}
Expand Down

0 comments on commit 54b28d8

Please sign in to comment.