Skip to content

Commit

Permalink
Replace DrupalStyle object with getIo (#285)
Browse files Browse the repository at this point in the history
  • Loading branch information
LOBsTerr authored and jmolivas committed Jan 19, 2018
1 parent 54b28d8 commit 8c0ded0
Show file tree
Hide file tree
Showing 14 changed files with 76 additions and 115 deletions.
20 changes: 9 additions & 11 deletions src/Command/AboutCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Drupal\Console\Core\Style\DrupalStyle;

/**
* Class AboutCommand
Expand All @@ -34,7 +33,6 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);
$application = $this->getApplication();

$aboutTitle = sprintf(
Expand All @@ -43,9 +41,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
$application->getVersion()
);

$io->setDecorated(false);
$io->title($aboutTitle);
$io->setDecorated(true);
$this->getIo()->setDecorated(false);
$this->getIo()->title($aboutTitle);
$this->getIo()->setDecorated(true);

$commands = [
'init' => [
Expand Down Expand Up @@ -73,13 +71,13 @@ protected function execute(InputInterface $input, OutputInterface $output)
];

foreach ($commands as $command => $commandInfo) {
$io->writeln($commandInfo[0]);
$io->comment(sprintf(' %s', $commandInfo[1]));
$io->newLine();
$this->getIo()->writeln($commandInfo[0]);
$this->getIo()->comment(sprintf(' %s', $commandInfo[1]));
$this->getIo()->newLine();
}

$io->writeln($this->trans('commands.self-update.description'));
$io->comment(' drupal self-update');
$io->newLine();
$this->getIo()->writeln($this->trans('commands.self-update.description'));
$this->getIo()->comment(' drupal self-update');
$this->getIo()->newLine();
}
}
33 changes: 14 additions & 19 deletions src/Command/Chain/ChainCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use Drupal\Console\Core\Utils\ChainQueue;
use Drupal\Console\Core\Utils\ChainDiscovery;
use Drupal\Console\Core\Command\Shared\InputTrait;
use Drupal\Console\Core\Style\DrupalStyle;

/**
* Class ChainCommand
Expand Down Expand Up @@ -71,8 +70,6 @@ protected function configure()
*/
protected function interact(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);

$file = $this->getFileOption();

$chainContent = $this->chainDiscovery
Expand All @@ -86,7 +83,7 @@ protected function interact(InputInterface $input, OutputInterface $output)

foreach ($inlinePlaceHolders as $inlinePlaceHolder => $inlinePlaceHolderValue) {
if (is_array($inlinePlaceHolderValue)) {
$placeHolderValue = $io->choice(
$placeHolderValue = $this->getIo()->choice(
sprintf(
$this->trans('commands.chain.messages.select-value-for-placeholder'),
$inlinePlaceHolder
Expand All @@ -95,7 +92,7 @@ protected function interact(InputInterface $input, OutputInterface $output)
current($inlinePlaceHolderValue)
);
} else {
$placeHolderValue = $io->ask(
$placeHolderValue = $this->getIo()->ask(
sprintf(
$this->trans(
'commands.chain.messages.enter-value-for-placeholder'
Expand All @@ -114,13 +111,11 @@ protected function interact(InputInterface $input, OutputInterface $output)
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);

$interactive = false;

$file = $input->getOption('file');
if (!$file) {
$io->error($this->trans('commands.chain.messages.missing-file'));
$this->getIo()->error($this->trans('commands.chain.messages.missing-file'));

return 1;
}
Expand All @@ -129,7 +124,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$file = calculateRealPath($file);

if (!$fileSystem->exists($file)) {
$io->error(
$this->getIo()->error(
sprintf(
$this->trans('commands.chain.messages.invalid-file'),
$file
Expand All @@ -150,14 +145,14 @@ protected function execute(InputInterface $input, OutputInterface $output)
->extractInlinePlaceHolders($chainContent);

if ($inlinePlaceHolders) {
$io->error(
$this->getIo()->error(
sprintf(
$this->trans('commands.chain.messages.missing-inline-placeholders'),
implode(', ', array_keys($inlinePlaceHolders))
)
);

$io->info(
$this->getIo()->info(
$this->trans(
'commands.chain.messages.set-inline-placeholders'
)
Expand All @@ -170,7 +165,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
strtoupper($inlinePlaceHolder)
);

$io->block($missingInlinePlaceHoldersMessage);
$this->getIo()->block($missingInlinePlaceHoldersMessage);
}

return 1;
Expand All @@ -180,7 +175,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$environmentPlaceHolders = $this->chainDiscovery
->extractEnvironmentPlaceHolders($chainContent);
if ($environmentPlaceHolders) {
$io->error(
$this->getIo()->error(
sprintf(
$this->trans(
'commands.chain.messages.missing-environment-placeholders'
Expand All @@ -192,7 +187,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
)
);

$io->info(
$this->getIo()->info(
$this->trans(
'commands.chain.messages.set-environment-placeholders'
)
Expand All @@ -205,7 +200,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
strtoupper($envPlaceHolder)
);

$io->block($missingEnvironmentPlaceHoldersMessage);
$this->getIo()->block($missingEnvironmentPlaceHoldersMessage);
}

return 1;
Expand Down Expand Up @@ -254,8 +249,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
continue;
}

$io->text($command['command']);
$io->newLine();
$this->getIo()->text($command['command']);
$this->getIo()->newLine();

$input = new ArrayInput($moduleInputs);
if (!is_null($interactive)) {
Expand All @@ -264,10 +259,10 @@ protected function execute(InputInterface $input, OutputInterface $output)

$allowFailure = array_key_exists('allow_failure', $command)?$command['allow_failure']:false;
try {
$callCommand->run($input, $io);
$callCommand->run($input, $this->getIo());
} catch (\Exception $e) {
if (!$allowFailure) {
$io->error($e->getMessage());
$this->getIo()->error($e->getMessage());
return 1;
}
}
Expand Down
15 changes: 6 additions & 9 deletions src/Command/CheckCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use Drupal\Console\Core\Utils\ConfigurationManager;
use Drupal\Console\Core\Utils\RequirementChecker;
use Drupal\Console\Core\Utils\ChainQueue;
use Drupal\Console\Core\Style\DrupalStyle;

/**
* Class CheckCommand
Expand Down Expand Up @@ -70,8 +69,6 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);

$checks = $this->requirementChecker->getCheckResult();
if (!$checks) {
$phpCheckFile = $this->configurationManager
Expand All @@ -81,7 +78,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

if (!$checks['php']['valid']) {
$io->error(
$this->getIo()->error(
sprintf(
$this->trans('commands.check.messages.php-invalid'),
$checks['php']['current'],
Expand All @@ -94,7 +91,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

if ($extensions = $checks['extensions']['required']['missing']) {
foreach ($extensions as $extension) {
$io->error(
$this->getIo()->error(
sprintf(
$this->trans('commands.check.messages.extension-missing'),
$extension
Expand All @@ -105,7 +102,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

if ($extensions = $checks['extensions']['recommended']['missing']) {
foreach ($extensions as $extension) {
$io->commentBlock(
$this->getIo()->commentBlock(
sprintf(
$this->trans(
'commands.check.messages.extension-recommended'
Expand All @@ -118,7 +115,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

if ($configurations = $checks['configurations']['required']['missing']) {
foreach ($configurations as $configuration) {
$io->error(
$this->getIo()->error(
sprintf(
$this->trans('commands.check.messages.configuration-missing'),
$configuration
Expand All @@ -129,7 +126,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

if ($configurations = $checks['configurations']['required']['overwritten']) {
foreach ($configurations as $configuration => $overwritten) {
$io->commentBlock(
$this->getIo()->commentBlock(
sprintf(
$this->trans(
'commands.check.messages.configuration-overwritten'
Expand All @@ -142,7 +139,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

if ($this->requirementChecker->isValid() && !$this->requirementChecker->isOverwritten()) {
$io->success(
$this->getIo()->success(
$this->trans('commands.check.messages.success')
);
}
Expand Down
8 changes: 3 additions & 5 deletions src/Command/Debug/ChainCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use Symfony\Component\Console\Output\OutputInterface;
use Drupal\Console\Core\Command\Command;
use Drupal\Console\Core\Utils\ChainDiscovery;
use Drupal\Console\Core\Style\DrupalStyle;

/**
* Class ChainCommand
Expand Down Expand Up @@ -54,12 +53,11 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);
$files = $this->chainDiscovery->getChainFiles();

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

$tableHeader = [
$this->trans('commands.debug.chain.messages.file')
Expand All @@ -70,7 +68,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$tableRows[] = $file;
}

$io->table($tableHeader, $tableRows);
$this->getIo()->table($tableHeader, $tableRows);
}

return 0;
Expand Down
7 changes: 2 additions & 5 deletions src/Command/Debug/SettingsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use Symfony\Component\Console\Output\OutputInterface;
use Drupal\Console\Core\Command\Command;
use Drupal\Console\Core\Utils\ConfigurationManager;
use Drupal\Console\Core\Style\DrupalStyle;
use Symfony\Component\Yaml\Yaml;

/**
Expand Down Expand Up @@ -55,16 +54,14 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);

$configuration = $this->configurationManager->getConfiguration();
$configApplication['application'] = $configuration->getRaw('application');

unset($configApplication['application']['autowire']);
unset($configApplication['application']['languages']);

$io->write(Yaml::dump($configApplication, 6, 2));
$io->newLine();
$this->getIo()->write(Yaml::dump($configApplication, 6, 2));
$this->getIo()->newLine();

return 0;
}
Expand Down
17 changes: 7 additions & 10 deletions src/Command/Debug/SiteCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use Symfony\Component\Yaml\Dumper;
use Drupal\Console\Core\Command\Command;
use Drupal\Console\Core\Utils\ConfigurationManager;
use Drupal\Console\Core\Style\DrupalStyle;

/**
* Class SiteCommand
Expand Down Expand Up @@ -68,12 +67,10 @@ public function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);

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

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

return 1;
}
Expand All @@ -91,16 +88,16 @@ function ($element) use ($key) {
$environments
);

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

return 0;
}

$targetConfig = $this->configurationManager->readTarget($target);
if (!$targetConfig) {
$io->error($this->trans('commands.debug.site.messages.invalid-site'));
$this->getIo()->error($this->trans('commands.debug.site.messages.invalid-site'));

return 1;
}
Expand All @@ -115,13 +112,13 @@ function ($element) use ($key) {
$val = &$val[$property_key];
}

$io->writeln($val);
$this->getIo()->writeln($val);
return 0;
}

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

return 0;
}
Expand Down
Loading

0 comments on commit 8c0ded0

Please sign in to comment.