Skip to content

Commit

Permalink
[console] Replace DrupalStyle object usage. Fix #3685 (#3691)
Browse files Browse the repository at this point in the history
* Add validator of HTTP methods. Move list of http methods to separate method and add settings for it. Change twig template to generate the methods based on HTTP methods accrodingly

* Remove create of DrupalStyle object, replace variable  with the method ->getIo, remove useless use statements, Update confirmation of generation call. Refactor methods using

* Remove double quotes in module info template
  • Loading branch information
LOBsTerr authored and jmolivas committed Jan 17, 2018
1 parent e468cbe commit 2bf3d00
Show file tree
Hide file tree
Showing 178 changed files with 1,064 additions and 1,785 deletions.
14 changes: 5 additions & 9 deletions src/Command/Cache/RebuildCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
namespace Drupal\Console\Command\Cache;

use Drupal\Console\Core\Command\Command;
use Drupal\Console\Core\Style\DrupalStyle;
use Drupal\Console\Utils\DrupalApi;
use Drupal\Console\Utils\Site;
use Symfony\Component\Console\Input\InputArgument;
Expand Down Expand Up @@ -81,12 +80,11 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);
$cache = $input->getArgument('cache')?:'all';
$this->site->loadLegacyFile('/core/includes/utility.inc');

if ($cache && !$this->drupalApi->isValidCache($cache)) {
$io->error(
$this->getIo()->error(
sprintf(
$this->trans('commands.cache.rebuild.messages.invalid-cache'),
$cache
Expand All @@ -96,8 +94,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
return 1;
}

$io->newLine();
$io->comment($this->trans('commands.cache.rebuild.messages.rebuild'));
$this->getIo()->newLine();
$this->getIo()->comment($this->trans('commands.cache.rebuild.messages.rebuild'));

if ($cache === 'all') {
$this->drupalApi->drupal_rebuild(
Expand All @@ -109,7 +107,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$caches[$cache]->deleteAll();
}

$io->success($this->trans('commands.cache.rebuild.messages.completed'));
$this->getIo()->success($this->trans('commands.cache.rebuild.messages.completed'));

return 0;
}
Expand All @@ -119,13 +117,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
*/
protected function interact(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);

$cache = $input->getArgument('cache');
if (!$cache) {
$cacheKeys = array_keys($this->drupalApi->getCaches());

$cache = $io->choiceNoList(
$cache = $this->getIo()->choiceNoList(
$this->trans('commands.cache.rebuild.questions.cache'),
$cacheKeys,
'all'
Expand Down
6 changes: 2 additions & 4 deletions src/Command/Cache/TagInvalidateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

namespace Drupal\Console\Command\Cache;

use Drupal\Console\Core\Style\DrupalStyle;
use Drupal\Core\Cache\CacheTagsInvalidatorInterface;
use Drupal\Console\Core\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
Expand Down Expand Up @@ -53,17 +52,16 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);
$tags = $input->getArgument('tag');

$io->comment(
$this->getIo()->comment(
sprintf(
$this->trans('commands.cache.tag.invalidate.messages.start'),
implode(', ', $tags)
)
);

$this->invalidator->invalidateTags($tags);
$io->success($this->trans('commands.cache.tag.invalidate.messages.completed'));
$this->getIo()->success($this->trans('commands.cache.tag.invalidate.messages.completed'));
}
}
25 changes: 10 additions & 15 deletions src/Command/ComposerizeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Drupal\Console\Command;

use Drupal\Console\Core\Style\DrupalStyle;
use Drupal\Console\Extension\Manager;
use Drupal\Console\Core\Utils\DrupalFinder;
use Symfony\Component\Console\Input\InputInterface;
Expand Down Expand Up @@ -75,10 +74,6 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
/**
* @var DrupalStyle $io
*/
$io = new DrupalStyle($input, $output);
$includeVersion = $input->getOption('include-version');
$showPackages = $input->getOption('show-packages')?:false;

Expand Down Expand Up @@ -106,13 +101,13 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

if ($showPackages) {
$io->comment($this->trans('commands.composerize.messages.'.$type));
$this->getIo()->comment($this->trans('commands.composerize.messages.'.$type));
$tableHeader = [
$this->trans('commands.composerize.messages.name'),
$this->trans('commands.composerize.messages.version'),
$this->trans('commands.composerize.messages.dependencies')
];
$io->table($tableHeader, $packages);
$this->getIo()->table($tableHeader, $packages);
}
foreach ($packages as $package) {
$module = str_replace('drupal/', '', $package['name']);
Expand All @@ -126,21 +121,21 @@ protected function execute(InputInterface $input, OutputInterface $output)
$composerCommand .= ' ';
}
}
$io->comment($this->trans('commands.composerize.messages.from'));
$io->simple($this->get('console.root'));
$io->newLine();
$io->comment($this->trans('commands.composerize.messages.execute'));
$io->simple($composerCommand);
$io->newLine();
$io->comment($this->trans('commands.composerize.messages.ignore'));
$this->getIo()->comment($this->trans('commands.composerize.messages.from'));
$this->getIo()->simple($this->get('console.root'));
$this->getIo()->newLine();
$this->getIo()->comment($this->trans('commands.composerize.messages.execute'));
$this->getIo()->simple($composerCommand);
$this->getIo()->newLine();
$this->getIo()->comment($this->trans('commands.composerize.messages.ignore'));

$webRoot = str_replace(
$this->drupalFinder->getComposerRoot() . '/',
'',
$this->drupalFinder->getDrupalRoot() . '/'
);

$io->writeln(
$this->getIo()->writeln(
[
' vendor/',
' '.$webRoot.'modules/contrib',
Expand Down
25 changes: 10 additions & 15 deletions src/Command/Config/DeleteCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Drupal\Core\Config\StorageInterface;
use Drupal\Core\Config\CachedStorage;
use Drupal\Core\Config\ConfigFactory;
use Drupal\Console\Core\Style\DrupalStyle;

class DeleteCommand extends Command
{
Expand Down Expand Up @@ -78,11 +77,9 @@ protected function configure()
*/
protected function interact(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);

$type = $input->getArgument('type');
if (!$type) {
$type = $io->choiceNoList(
$type = $this->getIo()->choiceNoList(
$this->trans('commands.config.delete.arguments.type'),
['active', 'staging'],
'active'
Expand All @@ -92,7 +89,7 @@ protected function interact(InputInterface $input, OutputInterface $output)

$name = $input->getArgument('name');
if (!$name) {
$name = $io->choiceNoList(
$name = $this->getIo()->choiceNoList(
$this->trans('commands.config.delete.arguments.name'),
$this->getAllConfigNames(),
'all'
Expand All @@ -106,30 +103,28 @@ protected function interact(InputInterface $input, OutputInterface $output)
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);

$type = $input->getArgument('type');
if (!$type) {
$io->error($this->trans('commands.config.delete.errors.type'));
$this->getIo()->error($this->trans('commands.config.delete.errors.type'));
return 1;
}

$name = $input->getArgument('name');
if (!$name) {
$io->error($this->trans('commands.config.delete.errors.name'));
$this->getIo()->error($this->trans('commands.config.delete.errors.name'));
return 1;
}

$configStorage = ('active' === $type) ? $this->configStorage : $this->configStorageSync;

if (!$configStorage) {
$io->error($this->trans('commands.config.delete.errors.config-storage'));
$this->getIo()->error($this->trans('commands.config.delete.errors.config-storage'));
return 1;
}

if ('all' === $name) {
$io->commentBlock($this->trans('commands.config.delete.warnings.undo'));
if ($io->confirm($this->trans('commands.config.delete.questions.sure'))) {
$this->getIo()->commentBlock($this->trans('commands.config.delete.warnings.undo'));
if ($this->getIo()->confirm($this->trans('commands.config.delete.questions.sure'))) {
if ($configStorage instanceof FileStorage) {
$configStorage->deleteAll();
} else {
Expand All @@ -138,7 +133,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
}
}

$io->success($this->trans('commands.config.delete.messages.all'));
$this->getIo()->success($this->trans('commands.config.delete.messages.all'));

return 0;
}
Expand All @@ -151,7 +146,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$this->removeConfig($name);
}

$io->success(
$this->getIo()->success(
sprintf(
$this->trans('commands.config.delete.messages.deleted'),
$name
Expand All @@ -161,7 +156,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

$message = sprintf($this->trans('commands.config.delete.errors.not-exists'), $name);
$io->error($message);
$this->getIo()->error($message);

return 1;
}
Expand Down
13 changes: 4 additions & 9 deletions src/Command/Config/DiffCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use Drupal\Console\Core\Command\Command;
use Drupal\Core\Config\CachedStorage;
use Drupal\Core\Config\ConfigManager;
use Drupal\Console\Core\Style\DrupalStyle;

class DiffCommand extends Command
{
Expand Down Expand Up @@ -85,11 +84,10 @@ protected function configure()
protected function interact(InputInterface $input, OutputInterface $output)
{
global $config_directories;
$io = new DrupalStyle($input, $output);

$directory = $input->getArgument('directory');
if (!$directory) {
$directory = $io->choice(
$directory = $this->getIo()->choice(
$this->trans('commands.config.diff.questions.directories'),
$config_directories,
CONFIG_SYNC_DIRECTORY
Expand All @@ -105,7 +103,6 @@ protected function interact(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output)
{
global $config_directories;
$io = new DrupalStyle($input, $output);
$directory = $input->getArgument('directory') ?: CONFIG_SYNC_DIRECTORY;
if (array_key_exists($directory, $config_directories)) {
$directory = $config_directories[$directory];
Expand All @@ -126,18 +123,16 @@ protected function execute(InputInterface $input, OutputInterface $output)
$change_list[$collection] = $config_comparer->getChangelist(null, $collection);
}

$this->outputDiffTable($io, $change_list);
$this->outputDiffTable($change_list);
}

/**
* Ouputs a table of configuration changes.
*
* @param DrupalStyle $io
* The io.
* @param array $change_list
* The list of changes from the StorageComparer.
*/
protected function outputDiffTable(DrupalStyle $io, array $change_list)
protected function outputDiffTable(array $change_list)
{
$header = [
$this->trans('commands.config.diff.table.headers.collection'),
Expand All @@ -156,6 +151,6 @@ protected function outputDiffTable(DrupalStyle $io, array $change_list)
}
}
}
$io->table($header, $rows);
$this->getIo()->table($header, $rows);
}
}
13 changes: 4 additions & 9 deletions src/Command/Config/EditCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use Drupal\Core\Config\CachedStorage;
use Drupal\Core\Config\ConfigFactory;
use Drupal\Console\Core\Command\Command;
use Drupal\Console\Core\Style\DrupalStyle;
use Drupal\Console\Core\Utils\ConfigurationManager;

class EditCommand extends Command
Expand Down Expand Up @@ -81,8 +80,6 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);

$configName = $input->getArgument('config-name');
$editor = $input->getArgument('editor');
$config = $this->configFactory->getEditable($configName);
Expand All @@ -93,7 +90,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$fileSystem = new Filesystem();

if (!$configName) {
$io->error($this->trans('commands.config.edit.messages.no-config'));
$this->getIo()->error($this->trans('commands.config.edit.messages.no-config'));

return 1;
}
Expand All @@ -102,7 +99,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$fileSystem->mkdir($temporaryDirectory);
$fileSystem->dumpFile($configFile, $this->getYamlConfig($configName));
} catch (IOExceptionInterface $e) {
$io->error($this->trans('commands.config.edit.messages.no-directory').' '.$e->getPath());
$this->getIo()->error($this->trans('commands.config.edit.messages.no-directory').' '.$e->getPath());

return 1;
}
Expand All @@ -122,7 +119,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

if (!$process->isSuccessful()) {
$io->error($process->getErrorOutput());
$this->getIo()->error($process->getErrorOutput());
return 1;
}

Expand All @@ -131,12 +128,10 @@ protected function execute(InputInterface $input, OutputInterface $output)

protected function interact(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);

$configName = $input->getArgument('config-name');
if (!$configName) {
$configNames = $this->configFactory->listAll();
$configName = $io->choice(
$configName = $this->getIo()->choice(
$this->trans('commands.config.edit.messages.choose-configuration'),
$configNames
);
Expand Down
9 changes: 3 additions & 6 deletions src/Command/Config/ExportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use Symfony\Component\Console\Output\OutputInterface;
use Drupal\Console\Core\Command\Command;
use Symfony\Component\Filesystem\Filesystem;
use Drupal\Console\Core\Style\DrupalStyle;
use Drupal\Core\Config\ConfigManager;

class ExportCommand extends Command
Expand Down Expand Up @@ -82,8 +81,6 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);

$directory = $input->getOption('directory');
$tar = $input->getOption('tar');
$removeUuid = $input->getOption('remove-uuid');
Expand All @@ -97,7 +94,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
try {
$fileSystem->mkdir($directory);
} catch (IOExceptionInterface $e) {
$io->error(
$this->getIo()->error(
sprintf(
$this->trans('commands.config.export.messages.error'),
$e->getPath()
Expand Down Expand Up @@ -170,10 +167,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
}
}
} catch (\Exception $e) {
$io->error($e->getMessage());
$this->getIo()->error($e->getMessage());
}

$io->info(
$this->getIo()->info(
sprintf(
$this->trans('commands.config.export.messages.directory'),
$directory
Expand Down
Loading

0 comments on commit 2bf3d00

Please sign in to comment.