Permalink
Switch branches/tags
3.x 4.x 5.x 6.x-fulltest 6.x 7.x 8.x 9.5.x alias-search-fix annotation-drush7 avoid-header-interaction backend-stdin batch-no-output better-bootstrap-refactor better-site-alias-docs bootstrap-state-isolation cc-bootstrap-errs chmod-settings-8 chmod-settings command-cache commit-sut-aliases compatible-status completion config-alias-repl coveralls dcf-composerjson docs-update drop-symfony2 drupal-core-strict drush9-services-yml dsnopek-mysqli-extension-2 editor ensure-mysql-available environment-inc-cleanup everyone-luvs-global-drush exclude-vendor find-uri-from-cwd fix-6-backport fix-6 fix-defaults fix-double-exec fix-file-alias-path fix-getmultiple fix-max fix-unish-path-repo generic-alias gh-pages guard-service-cache hook-order inflect-alias-manager integration-tests-2 integration-tests-with-confirmations interact-hook isolation-via-test-scenarios luv-4-global-drush master-fulltest master merge-config-paths moar-testability mv-during-pm-download output-filter pass-unknown-to-site-local paths-for-local-redispatch-only php-72-isolation phpunit6 preflight-sitelocator preserve-contrib-dir-backport private-yml-parser process-replacement property-list psr-4 remote-sitespecs remote-unknown-commands remove-annotation-adapter remove-command-inc remove-sitealias rename-drush-service-cache sa-multipart-aliases shippable si-for-ci-drush8 si-for-ci si-profile simplified-site-aliases site-alias-location-filters sitealias-refactor skip-shippable sql-fetch ssh-tty-option support-docs symfony-dispatch-remove-contexts symfony-dispatch-remove-some-preflight tagged-services test-bootstrap-none test-symfony-dispatch unstructured-data-fields update-no-bootstrap use-mysqli useProcess user-check-if-blocked
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
103 lines (92 sloc) 2.61 KB
<?php
namespace Drush\Commands;
use Drush\Drush;
use Drush\Style\DrushStyle;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use Psr\Log\LoggerInterface;
use Robo\Common\ConfigAwareTrait;
use Robo\Contract\ConfigAwareInterface;
use Robo\Contract\IOAwareInterface;
use Robo\Common\IO;
use Symfony\Component\Console\Input\InputOption;
abstract class DrushCommands implements IOAwareInterface, LoggerAwareInterface, ConfigAwareInterface
{
// This is more readable.
const REQ=InputOption::VALUE_REQUIRED;
const OPT=InputOption::VALUE_OPTIONAL;
// Common exit codes.
const EXIT_SUCCESS = 0;
const EXIT_FAILURE = 1;
use LoggerAwareTrait;
use ConfigAwareTrait {
// Move aside this method so we can replace. See https://stackoverflow.com/a/37687295.
getConfig as ConfigAwareGetConfig;
}
use IO {
io as roboIo;
}
public function __construct()
{
}
/**
* Returns a logger object.
*
* @return LoggerInterface
*/
protected function logger()
{
return $this->logger;
}
/**
* Override Robo's IO function with our custom style.
*/
protected function io()
{
if (!$this->io) {
// Specify our own Style class when needed.
$this->io = new DrushStyle($this->input(), $this->output());
}
return $this->io;
}
/**
* Replaces same method in ConfigAwareTrait in order to provide a
* DrushConfig as return type. Helps with IDE completion.
*
* @see https://stackoverflow.com/a/37687295.
*
* @return \Drush\Config\DrushConfig
*/
public function getConfig()
{
return $this->ConfigAwareGetConfig();
}
/**
* Print the contents of a file.
*
* @param string $file
* Full path to a file.
*/
protected function printFile($file)
{
if ((substr($file, -4) == ".htm") || (substr($file, -5) == ".html")) {
$tmp_file = drush_tempnam(basename($file));
file_put_contents($tmp_file, drush_html_to_text(file_get_contents($file)));
$file = $tmp_file;
}
if (self::input()->isInteractive()) {
;
$process = Drush::process(['less', $file])->setTty(true);
if ($process->run() === 0) {
return;
} else {
$process = Drush::process(['more', $file]);
if ($process->run() === 0) {
return;
} else {
$this->output()->writeln(file_get_contents($file));
}
}
}
}
}