Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ services:
arguments: ['@console.root', '@console.configuration_manager']
console.count_code_lines:
class: Drupal\Console\Core\Utils\CountCodeLines
console.message_parser:
class: Drupal\Console\Core\Utils\MessageParser
# DrupalConsoleCore Commands
console.about:
class: Drupal\Console\Core\Command\AboutCommand
Expand Down
40 changes: 19 additions & 21 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ public function doRun(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);
$messages = [];
if ($this->container->hasParameter('console.messages')) {
$messages = $this->container->getParameter('console.messages');
}
$this->commandName = $this->getCommandName($input)?:'list';

$clear = $this->container->get('console.configuration_manager')
Expand Down Expand Up @@ -143,11 +146,13 @@ public function doRun(InputInterface $input, OutputInterface $output)

if (array_key_exists($this->commandName, $mappings)) {
$commandNameMap = $mappings[$this->commandName];
$messages['warning'][] = sprintf(
$this->trans('application.errors.renamed-command'),
$this->commandName,
$commandNameMap
);
$messages[] =[
'warning' => sprintf(
$this->trans('application.errors.renamed-command'),
$this->commandName,
$commandNameMap
)
];
$this->add(
$this->find($commandNameMap)->setAliases([$this->commandName])
);
Expand All @@ -160,11 +165,13 @@ public function doRun(InputInterface $input, OutputInterface $output)
$this->find($drushCommand)->setAliases([$this->commandName])
);
$isValidCommand = true;
$messages['warning'][] = sprintf(
$this->trans('application.errors.drush-command'),
$this->commandName,
$drushCommand
);
$messages[] = [
'warning' => sprintf(
$this->trans('application.errors.drush-command'),
$this->commandName,
$drushCommand
)
];
}

if (!$isValidCommand) {
Expand Down Expand Up @@ -198,17 +205,8 @@ public function doRun(InputInterface $input, OutputInterface $output)
);
}

if ($this->commandName == 'list') {
if ($this->container->hasParameter('console.warning')) {
$io->commentBlock(
$this->trans(
$this->container->getParameter('console.warning')
)
);
}
}

foreach ($messages as $type => $message) {
foreach ($messages as $key => $message) {
$type = key($message);
$io->$type($message);
}

Expand Down
30 changes: 30 additions & 0 deletions src/Utils/MessageParser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Drupal\Console\Core\Utils;

/**
* Class MessageParser
* @package Drupal\Console\Core\Utils
*/
class MessageParser {

/**
* @param $container
* @param $type
* @param $message
*/
public function addMessage($container, $type, $message) {

$messages = [];
if ($container->hasParameter('console.messages')) {
$messages = $container->getParameter('console.messages');
}
$messages[] = [ $type => $message ];

$container
->setParameter(
'console.messages',
$messages
);
}
}