2 namespace Drush\Commands;
4 use Drush\Style\DrushStyle;
5 use Psr\Log\LoggerAwareInterface;
6 use Psr\Log\LoggerAwareTrait;
7 use Psr\Log\LoggerInterface;
8 use Robo\Common\ConfigAwareTrait;
9 use Robo\Contract\ConfigAwareInterface;
10 use Robo\Contract\IOAwareInterface;
12 use Symfony\Component\Console\Input\InputOption;
14 abstract class DrushCommands implements IOAwareInterface, LoggerAwareInterface, ConfigAwareInterface
16 // This is more readable.
17 const REQ=InputOption::VALUE_REQUIRED;
18 const OPT=InputOption::VALUE_OPTIONAL;
21 use ConfigAwareTrait {
22 // Move aside this method so we can replace. See https://stackoverflow.com/a/37687295.
23 getConfig as ConfigAwareGetConfig;
29 public function __construct()
34 * Returns a logger object.
36 * @return LoggerInterface
38 protected function logger()
44 * Override Robo's IO function with our custom style.
46 protected function io()
49 // Specify our own Style class when needed.
50 $this->io = new DrushStyle($this->input(), $this->output());
56 * Replaces same method in ConfigAwareTrait in order to provide a
57 * DrushConfig as return type. Helps with IDE completion.
59 * @see https://stackoverflow.com/a/37687295.
61 * @return \Drush\Config\DrushConfig
63 public function getConfig()
65 return $this->ConfigAwareGetConfig();
69 * Print the contents of a file.
72 * Full path to a file.
74 protected function printFile($file)
76 if ((substr($file, -4) == ".htm") || (substr($file, -5) == ".html")) {
77 $tmp_file = drush_tempnam(basename($file));
78 file_put_contents($tmp_file, drush_html_to_text(file_get_contents($file)));
82 if (self::input()->isInteractive()) {
83 if (drush_shell_exec_interactive("less %s", $file)) {
85 } elseif (drush_shell_exec_interactive("more %s", $file)) {
88 $this->output()->writeln(file_get_contents($file));