Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Symfony dispatch remove contexts #2941

Merged
merged 4 commits into from
Sep 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
//
Expand All @@ -54,23 +58,20 @@ 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
// --choice
// --ignored-modules
// --no-label
// --label-separator
// --nocolor
// --cache-default-class
// --cache-class-<bin>
// --confirm-rollback
Expand All @@ -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.')
Expand Down
26 changes: 10 additions & 16 deletions src/Commands/DrushCommands.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

namespace Drush\Commands;

use Drush\Style\DrushStyle;
Expand Down Expand Up @@ -51,26 +50,21 @@ protected function io()
*/
public static function printFile($file)
{
// Don't even bother to print the file in --no mode
if (drush_get_context('DRUSH_NEGATIVE')) {
return;
}

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;
}
// Do not wait for user input in --yes or --pipe modes
if (drush_get_context('DRUSH_PIPE')) {
drush_print_pipe(file_get_contents($file));
} elseif (drush_get_context('DRUSH_AFFIRMATIVE')) {
drush_print(file_get_contents($file));
} elseif (drush_shell_exec_interactive("less %s", $file)) {
return;
} elseif (drush_shell_exec_interactive("more %s", $file)) {
return;
} else {
drush_print(file_get_contents($file));

if (self::input()->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));
}
}
}
}
2 changes: 1 addition & 1 deletion src/Commands/core/DrupliconCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand Down
3 changes: 2 additions & 1 deletion src/Commands/core/EditCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
namespace Drush\Commands\core;

use Drush\Commands\DrushCommands;
use Drush\Drush;

class EditCommands extends DrushCommands
{
Expand Down Expand Up @@ -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')) {
Expand Down
12 changes: 4 additions & 8 deletions src/Commands/core/NotifyCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/core/RsyncCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand Down
3 changes: 2 additions & 1 deletion src/Commands/core/SiteCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use Drush\Commands\DrushCommands;

use Drush\Drush;
use Drush\SiteAlias\SiteAliasManagerAwareInterface;
use Drush\SiteAlias\SiteAliasManagerAwareTrait;
use Drush\SiteAlias\SiteAliasName;
Expand Down Expand Up @@ -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);
Expand Down
46 changes: 26 additions & 20 deletions src/Commands/core/StatusCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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();
Expand All @@ -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');
}
}
Expand All @@ -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';
}
Expand All @@ -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;
Expand Down Expand Up @@ -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()) {
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/core/XhprofCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.'));
}
Expand Down
8 changes: 4 additions & 4 deletions src/Commands/help/HelpCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
}
Expand All @@ -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 {
Expand Down
28 changes: 1 addition & 27 deletions src/Commands/help/ListCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 . ':', ''];
Expand Down
Loading