diff --git a/src/Application.php b/src/Application.php index eab28e0818..898cf32484 100644 --- a/src/Application.php +++ b/src/Application.php @@ -30,7 +30,7 @@ public function __construct($name, $version) // --alias-path // --local // - // Global options registerd with Symfony: + // Global options registered with Symfony: // // --remote-host // --remote-user @@ -43,6 +43,10 @@ public function __construct($name, $version) // --verbose / -v // --help // --quiet + // --debug / -d : equivalent to -vv + // --yes / -y : equivalent to --no-interaction + // --nocolor : equivalent to --no-ansi + // // // No longer supported // @@ -54,15 +58,13 @@ public function __construct($name, $version) // --strict Not supported by Symfony // --interactive If command isn't -n, then it is interactive // --command-specific Now handled by consolidation/config component - // + // --php If needed prefix command with PATH=/path/to/php:$PATH. Also see #env_vars in site aliases. + // --php-options + // --pipe // Not handled yet (to be implemented): // - // --debug / -d + // --uri / -l - // --yes / -y - // --pipe - // --php - // --php-options // --tty // --exclude // --backend @@ -70,7 +72,6 @@ public function __construct($name, $version) // --ignored-modules // --no-label // --label-separator - // --nocolor // --cache-default-class // --cache-class- // --confirm-rollback @@ -86,6 +87,17 @@ public function __construct($name, $version) // --path-aliases // --ssh-options + + $this->getDefinition() + ->addOption( + new InputOption('--debug', 'd', InputOption::VALUE_NONE, 'Equivalent to -vv') + ); + + $this->getDefinition() + ->addOption( + new InputOption('--yes', 'y', InputOption::VALUE_NONE, 'Equivalent to --no-interaction.') + ); + $this->getDefinition() ->addOption( new InputOption('--remote-host', null, InputOption::VALUE_REQUIRED, 'Run on a remote server.') diff --git a/src/Commands/DrushCommands.php b/src/Commands/DrushCommands.php index 5f5df1e553..2ce92ad301 100644 --- a/src/Commands/DrushCommands.php +++ b/src/Commands/DrushCommands.php @@ -1,5 +1,4 @@ isInteractive()) { + if (drush_shell_exec_interactive("less %s", $file)) { + return; + } elseif (drush_shell_exec_interactive("more %s", $file)) { + return; + } else { + drush_print(file_get_contents($file)); + } } } } diff --git a/src/Commands/core/DrupliconCommands.php b/src/Commands/core/DrupliconCommands.php index 348a3a585f..e467ed2de6 100644 --- a/src/Commands/core/DrupliconCommands.php +++ b/src/Commands/core/DrupliconCommands.php @@ -28,7 +28,7 @@ public function druplicon($result, CommandData $commandData) $this->printed = true; $annotationData = $commandData->annotationData(); $commandName = $annotationData['command']; - if ($commandData->input()->getOption('druplicon')) { + if ($commandData->input()->hasOption('druplicon') && $commandData->input()->getOption('druplicon')) { $this->logger()->debug(dt('Displaying Druplicon for "!command" command.', array('!command' => $commandName))); $misc_dir = DRUSH_BASE_PATH . '/misc'; if (drush_get_context('DRUSH_NOCOLOR')) { diff --git a/src/Commands/core/EditCommands.php b/src/Commands/core/EditCommands.php index da4ea1e23e..141689f186 100644 --- a/src/Commands/core/EditCommands.php +++ b/src/Commands/core/EditCommands.php @@ -2,6 +2,7 @@ namespace Drush\Commands\core; use Drush\Commands\DrushCommands; +use Drush\Drush; class EditCommands extends DrushCommands { @@ -84,7 +85,7 @@ public function load($headers = true) $aliases_header = array('aliases' => '-- Aliases --'); } } - if ($site_root = drush_get_context('DRUSH_DRUPAL_SITE_ROOT')) { + if ($site_root = Drush::bootstrap()->confPath()) { $path = realpath($site_root . '/settings.php'); $drupal[$path] = $path; if (file_exists($site_root . '/settings.local.php')) { diff --git a/src/Commands/core/NotifyCommands.php b/src/Commands/core/NotifyCommands.php index a531e9fd6e..522cbfc7ca 100644 --- a/src/Commands/core/NotifyCommands.php +++ b/src/Commands/core/NotifyCommands.php @@ -39,19 +39,15 @@ public function registerShutdown(CommandData $commandData) public function shutdown(CommandData $commandData) { - $cmd = $commandData->input()->getFirstArgument(); + + $input = $commandData->input(); + $cmd = $input->getFirstArgument(); if (empty($cmd)) { return; } - // pm-download handles its own notification. - if ($cmd != 'pm-download' && self::isAllowed($commandData)) { - $msg = $commandData->annotationData()->get('notify', dt("Command '!command' completed.", array('!command' => $cmd))); - $this->shutdownSend($msg, $commandData); - } - - if ($commandData->input()->getOption('notify') && drush_get_error()) { + if ($input->hasOption('notify') && $input->getOption('notify') && drush_get_error()) { // If the only error is that notify failed, do not try to notify again. $log = drush_get_error_log(); if (count($log) == 1 && array_key_exists('NOTIFY_COMMAND_NOT_FOUND', $log)) { diff --git a/src/Commands/core/RsyncCommands.php b/src/Commands/core/RsyncCommands.php index 12b09202be..bf4b2c936b 100644 --- a/src/Commands/core/RsyncCommands.php +++ b/src/Commands/core/RsyncCommands.php @@ -80,7 +80,7 @@ public function rsyncOptions($options) } $mode = '-'. $options['mode']; - if (drush_get_context('DRUSH_VERBOSE')) { + if ($this->io()->isVerbose()) { $mode .= 'v'; $verbose = ' --stats --progress'; } diff --git a/src/Commands/core/SiteCommands.php b/src/Commands/core/SiteCommands.php index b8eed5f9b9..2703a47497 100644 --- a/src/Commands/core/SiteCommands.php +++ b/src/Commands/core/SiteCommands.php @@ -3,6 +3,7 @@ use Drush\Commands\DrushCommands; +use Drush\Drush; use Drush\SiteAlias\SiteAliasManagerAwareInterface; use Drush\SiteAlias\SiteAliasManagerAwareTrait; use Drush\SiteAlias\SiteAliasName; @@ -219,7 +220,7 @@ public static function siteAliasList() public static function siteSiteList() { $site_list = array(); - $base_path = drush_get_context('DRUSH_DRUPAL_ROOT'); + $base_path = Drush::bootstrapManager()->getRoot(); if ($base_path) { $base_path .= '/sites'; $files = drush_scan_directory($base_path, '/settings\.php/', array('.', '..', 'CVS', 'all'), 0, 1); diff --git a/src/Commands/core/StatusCommands.php b/src/Commands/core/StatusCommands.php index b819912def..b8b69ecb97 100644 --- a/src/Commands/core/StatusCommands.php +++ b/src/Commands/core/StatusCommands.php @@ -5,6 +5,7 @@ use Consolidation\OutputFormatters\StructuredData\PropertyList; use Drupal\Core\StreamWrapper\PrivateStream; use Drupal\Core\StreamWrapper\PublicStream; +use Drush\Boot\BootstrapManager; use Drush\Commands\DrushCommands; use Drush\Drush; use Drush\Sql\SqlBase; @@ -17,7 +18,7 @@ class StatusCommands extends DrushCommands /** * @command core-status * @param $filter A field to filter on. @deprecated - use --field option instead. - * @option project A comma delimited list of projects. their paths will be added to path-aliases section. + * @option project A comma delimited list of projects. Their paths will be added to path-aliases section. * @aliases status, st *n * @table-style compact @@ -77,15 +78,16 @@ public function status($filter = '', $options = ['project' => '', 'format' => 't public static function getPropertyList($options) { - $phase = drush_get_context('DRUSH_BOOTSTRAP_PHASE'); - if ($drupal_root = drush_get_context('DRUSH_DRUPAL_ROOT')) { + $boot_manager = Drush::bootstrapManager(); + $boot_object = Drush::bootstrap(); + if ($drupal_root = $boot_manager->getRoot()) { $status_table['drupal-version'] = drush_drupal_version(); - $boot_object = Drush::bootstrap(); $conf_dir = $boot_object->confPath(); $settings_file = "$conf_dir/settings.php"; $status_table['drupal-settings-file'] = file_exists($settings_file) ? $settings_file : ''; - if ($site_root = drush_get_context('DRUSH_DRUPAL_SITE_ROOT')) { - $status_table['uri'] = drush_get_context('DRUSH_URI'); + if ($boot_manager->hasBootstrapped(DRUSH_BOOTSTRAP_DRUPAL_SITE)) { + // @todo for some reason getUri() is returning null. + $status_table['uri'] = $boot_manager->getUri(); try { $sql = SqlBase::create($options); $db_spec = $sql->getDbSpec(); @@ -99,11 +101,11 @@ public static function getPropertyList($options) $status_table['db-password'] = isset($db_spec['password']) ? $db_spec['password'] : null; $status_table['db-name'] = isset($db_spec['database']) ? $db_spec['database'] : null; $status_table['db-port'] = isset($db_spec['port']) ? $db_spec['port'] : null; - if ($phase > DRUSH_BOOTSTRAP_DRUPAL_CONFIGURATION) { + if ($boot_manager->hasBootstrapped(DRUSH_BOOTSTRAP_DRUPAL_CONFIGURATION)) { $status_table['install-profile'] = $boot_object->getProfile(); - if ($phase > DRUSH_BOOTSTRAP_DRUPAL_DATABASE) { + if ($boot_manager->hasBootstrapped(DRUSH_BOOTSTRAP_DRUPAL_DATABASE)) { $status_table['db-status'] = dt('Connected'); - if ($phase >= DRUSH_BOOTSTRAP_DRUPAL_FULL) { + if ($boot_manager->hasBootstrapped(DRUSH_BOOTSTRAP_DRUPAL_FULL)) { $status_table['bootstrap'] = dt('Successful'); } } @@ -112,7 +114,7 @@ public static function getPropertyList($options) // Don't worry be happy. } } - if (drush_has_boostrapped(DRUSH_BOOTSTRAP_DRUPAL_FULL)) { + if ($boot_manager->hasBootstrapped(DRUSH_BOOTSTRAP_DRUPAL_FULL)) { $status_table['theme'] = \Drupal::config('system.theme')->get('default'); $status_table['admin-theme'] = $theme = \Drupal::config('system.theme')->get('admin') ?: 'seven'; } @@ -129,7 +131,7 @@ public static function getPropertyList($options) $alias_files = _drush_sitealias_find_alias_files(); $status_table['drush-alias-files'] = $alias_files; - $paths = self::pathAliases($options); + $paths = self::pathAliases($options, $boot_manager, $boot_object); if (!empty($paths)) { foreach ($paths as $target => $one_path) { $name = $target; @@ -168,38 +170,42 @@ public function adjustStatusOptions(CommandData $commandData) } } - public static function pathAliases($options) + /** + * @param array $options + * @param BootstrapManager $boot_manager + * @return array + */ + public static function pathAliases(array $options, BootstrapManager $boot_manager, $boot) { $paths = array(); $site_wide = 'sites/all'; - $boot = Drush::bootstrap(); - if ($drupal_root = drush_get_context('DRUSH_DRUPAL_ROOT')) { + if ($drupal_root = $boot_manager->getRoot()) { $paths['%root'] = $drupal_root; - if ($site_root = drush_get_context('DRUSH_DRUPAL_SITE_ROOT')) { + if ($site_root = $boot->confPath()) { $paths['%site'] = $site_root; - if (is_dir($modules_path = $boot->confPath() . '/modules')) { + if (is_dir($modules_path = $site_root . '/modules')) { $paths['%modules'] = $modules_path; } else { $paths['%modules'] = ltrim($site_wide . '/modules', '/'); } - if (is_dir($themes_path = $boot->confPath() . '/themes')) { + if (is_dir($themes_path = $site_root . '/themes')) { $paths['%themes'] = $themes_path; } else { $paths['%themes'] = ltrim($site_wide . '/themes', '/'); } - if (drush_has_boostrapped(DRUSH_BOOTSTRAP_DRUPAL_CONFIGURATION)) { + if ($boot_manager->hasBootstrapped(DRUSH_BOOTSTRAP_DRUPAL_CONFIGURATION)) { try { if (isset($GLOBALS['config_directories'])) { foreach ($GLOBALS['config_directories'] as $label => $unused) { $paths["%config-$label"] = config_get_config_directory($label); } } - } catch (Exception $e) { + } catch (\Exception $e) { // Nothing to do. } } - if (drush_has_boostrapped(DRUSH_BOOTSTRAP_DRUPAL_FULL)) { + if ($boot_manager->hasBootstrapped(DRUSH_BOOTSTRAP_DRUPAL_FULL)) { $paths['%files'] = PublicStream::basePath(); $paths['%temp'] = file_directory_temp(); if ($private_path = PrivateStream::basePath()) { diff --git a/src/Commands/core/XhprofCommands.php b/src/Commands/core/XhprofCommands.php index b36de160de..bbf87b7a26 100644 --- a/src/Commands/core/XhprofCommands.php +++ b/src/Commands/core/XhprofCommands.php @@ -64,7 +64,7 @@ public function xhprofInitialize(InputInterface $input, AnnotationData $annotati public static function xhprofIsEnabled(InputInterface $input) { - if ($input->getOption('xh-link')) { + if ($input->hasOption('xh-link') && $input->getOption('xh-link')) { if (!extension_loaded('xhprof') && !extension_loaded('tideways')) { throw new \Exception(dt('You must enable the xhprof or tideways PHP extensions in your CLI PHP in order to profile.')); } diff --git a/src/Commands/help/HelpCommands.php b/src/Commands/help/HelpCommands.php index 9817ad829a..ef7738efac 100644 --- a/src/Commands/help/HelpCommands.php +++ b/src/Commands/help/HelpCommands.php @@ -13,7 +13,7 @@ class HelpCommands extends DrushCommands * Display usage details for a command. * * @command help - * @param $name A command name + * @param $command_name A command name * @usage drush help pm-uninstall * Show help for a command. * @usage drush help pmu @@ -27,10 +27,10 @@ class HelpCommands extends DrushCommands * * @return \Consolidation\AnnotatedCommand\Help\HelpDocument */ - public function help($name, $options = ['format' => 'helpcli', 'include-field-labels' => false, 'table-style' => 'compact']) + public function help($command_name, $options = ['format' => 'helpcli', 'include-field-labels' => false, 'table-style' => 'compact']) { $application = Drush::getApplication(); - $command = $application->get($name); + $command = $application->get($command_name); if ($command instanceof AnnotatedCommand) { $command->optionsHook(); } @@ -49,7 +49,7 @@ public function help($name, $options = ['format' => 'helpcli', 'include-field-la */ public function validate(CommandData $commandData) { - $name = $commandData->input()->getArgument('name'); + $name = $commandData->input()->getArgument('command_name'); if (empty($name)) { throw new \Exception(dt("The help command requires that a command name be provided. Run `drush list` to see a list of available commands.")); } else { diff --git a/src/Commands/help/ListCommands.php b/src/Commands/help/ListCommands.php index 5cefbe6cd8..f892cef744 100644 --- a/src/Commands/help/ListCommands.php +++ b/src/Commands/help/ListCommands.php @@ -30,7 +30,7 @@ class ListCommands extends DrushCommands * * @return \DOMDocument */ - public function helpList($filter, $options = ['format' => 'listcli', 'raw' => false, 'filter' => null]) + public function helpList($filter = null, $options = ['format' => 'listcli', 'raw' => false, 'filter' => null]) { $application = Drush::getApplication(); annotation_adapter_add_legacy_commands_to_application($application); @@ -123,32 +123,6 @@ public static function renderListCLI($application, $namespaced, $output, $preamb ->writeln($preamble); $output->writeln(''); - // For now ,this table does not need TableFormatter. - $table = new Table($output); - $table->setStyle('compact'); - $global_options_help = drush_get_global_options(true); - $options = $application->getDefinition()->getOptions(); - // Only display this table for Drush help, not 'generate' command. - if ($application->getName() == 'Drush Commandline Tool') { - $table->addRow([new TableCell('Global options. See `drush topic core-global-options` for the full list.', array('colspan' => 2))]); - foreach ($global_options_help as $key => $help) { - $data = [ - 'name' => '--' . $options[$key]->getName(), - 'description' => $help['description'], - // Not using $options[$key]->getDescription() as description is too long for -v - 'accept_value' => $options[$key]->acceptValue(), - 'is_value_required' => $options[$key]->isValueRequired(), - 'shortcut' => $options[$key]->getShortcut(), - ]; - $table->addRow([ - HelpCLIFormatter::formatOptionKeys($data), - HelpCLIFormatter::formatOptionDescription($data) - ]); - } - $table->addRow(['', '']); - $table->render(); - } - $rows[] = ['Available commands:', '']; foreach ($namespaced as $namespace => $list) { $rows[] = [$namespace . ':', '']; diff --git a/src/Drupal/Commands/core/CliCommands.php b/src/Drupal/Commands/core/CliCommands.php index 25991feec0..54c376463e 100644 --- a/src/Drupal/Commands/core/CliCommands.php +++ b/src/Drupal/Commands/core/CliCommands.php @@ -9,12 +9,16 @@ use Drush\Psysh\DrushHelpCommand; use Drupal\Component\Assertion\Handle; use Drush\Psysh\Shell; +use Drush\SiteAlias\SiteAliasManagerAwareInterface; +use Drush\SiteAlias\SiteAliasManagerAwareTrait; use Psy\Configuration; use Psy\VersionUpdater\Checker; -class CliCommands extends DrushCommands +class CliCommands extends DrushCommands implements SiteAliasManagerAwareInterface { + use SiteAliasManagerAwareTrait; + /** * Drush's PHP Shell. * @@ -180,7 +184,7 @@ protected function historyPath(array $options) if ($site_name) { $site_suffix = $site_name; } else { - $drupal_root = drush_get_context('DRUSH_DRUPAL_ROOT'); + $drupal_root = Drush::bootstrapManager()->getRoot(); $site_suffix = md5($drupal_root); } @@ -190,7 +194,7 @@ protected function historyPath(array $options) $full_path = "$cli_directory/$file_name"; // Output the history path if verbose is enabled. - if (drush_get_context('DRUSH_VERBOSE')) { + if ($this->io()->isVerbose()) { $this->logger()->log(LogLevel::SUCCESS, dt('History: @full_path', ['@full_path' => $full_path])); } diff --git a/src/Drupal/Commands/core/DrupalCommands.php b/src/Drupal/Commands/core/DrupalCommands.php index c69738ae69..ea735bb76b 100644 --- a/src/Drupal/Commands/core/DrupalCommands.php +++ b/src/Drupal/Commands/core/DrupalCommands.php @@ -6,6 +6,7 @@ use Drupal\Core\Extension\ModuleHandlerInterface; use Drush\Commands\DrushCommands; use Drush\Drupal\DrupalUtil; +use Drush\Drush; class DrupalCommands extends DrushCommands { @@ -89,7 +90,7 @@ public function twigCompile() foreach ($searchpaths as $searchpath) { foreach ($file = drush_scan_directory($searchpath, '/\.html.twig/', array('tests')) as $file) { - $relative = str_replace(drush_get_context('DRUSH_DRUPAL_ROOT') . '/', '', $file->filename); + $relative = str_replace(Drush::bootstrapManager()->getRoot() . '/', '', $file->filename); // @todo Dynamically disable twig debugging since there is no good info there anyway. twig_render_template($relative, array('theme_hook_original' => '')); $this->logger() diff --git a/src/Preflight/Preflight.php b/src/Preflight/Preflight.php index d9e67c8ba3..becd8f2b6f 100644 --- a/src/Preflight/Preflight.php +++ b/src/Preflight/Preflight.php @@ -201,11 +201,6 @@ protected function doRun($argv) $discovery = $this->commandDiscovery(); $commandClasses = $discovery->discover($searchpath, '\Drush'); - // For now: use Symfony's built-in help, as Drush's version - // assumes we are using the legacy Drush dispatcher. - unset($commandClasses[dirname(__DIR__) . '/Commands/help/HelpCommands.php']); - unset($commandClasses[dirname(__DIR__) . '/Commands/help/ListCommands.php']); - // Use the robo runner to register commands with Symfony application. $runner = new \Robo\Runner(); $runner->registerCommandClasses($application, $commandClasses); diff --git a/src/Style/DrushStyle.php b/src/Style/DrushStyle.php index c99399f35b..ff12e83f27 100644 --- a/src/Style/DrushStyle.php +++ b/src/Style/DrushStyle.php @@ -26,20 +26,4 @@ public function choice($question, array $choices, $default = null) return array_search($return, $choices); } } - - public function confirm($question, $default = true) - { - // Automatically accept confirmations if the --yes argument was supplied. - if (drush_get_context('DRUSH_AFFIRMATIVE')) { - $this->comment($question . ': yes.'); - return true; - } // Automatically cancel confirmations if the --no argument was supplied. - elseif (drush_get_context('DRUSH_NEGATIVE')) { - $this->warning($question . ': no.'); - return false; - } - - $return = parent::confirm($question, $default); - return $return; - } }