Skip to content

Commit

Permalink
Convert browse to an annotated command (master). (#2341)
Browse files Browse the repository at this point in the history
Convert browse to an annotated command
  • Loading branch information
weitzman authored Sep 12, 2016
1 parent 31e6cb2 commit b0a27da
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 61 deletions.
57 changes: 0 additions & 57 deletions commands/core/browse.drush.inc

This file was deleted.

2 changes: 1 addition & 1 deletion includes/command.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1530,7 +1530,7 @@ function _drush_add_commandfiles($searchpath, $phase = NULL, $reset = FALSE) {
// Assemble a cid specific to the bootstrap phase and searchpaths.
// Bump $cf_version when making a change to a dev version of Drush
// that invalidates the commandfile cache.
$cf_version = 7;
$cf_version = 8;
$cid = drush_get_cid('commandfiles-' . $phase, array(), array_merge($searchpath, array($cf_version)));
$command_cache = drush_cache_get($cid);
if (isset($command_cache->data)) {
Expand Down
16 changes: 13 additions & 3 deletions includes/complete.inc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

use Drush\Log\LogLevel;
use Consolidation\AnnotatedCommand\Parser\CommandInfo;

/**
* @file
Expand Down Expand Up @@ -504,8 +504,18 @@ function drush_complete_rebuild_arguments($command) {
// the bootstrap level, and perhaps bootstrap higher in extraordinary cases.
drush_bootstrap_max(DRUSH_BOOTSTRAP_DRUPAL_SITE);
$commands = drush_get_commands();
$hook = str_replace("-", "_", $commands[$command]['command-hook']);
$result = drush_command_invoke_all($hook . '_complete');
$command_info = $commands[$command];
if ($callback = $command_info['annotated-command-callback']) {
list($classname, $method) = $callback;
$commandInfo = new CommandInfo($classname, $method);
if ($callable = $commandInfo->getAnnotation('complete')) {
$result = call_user_func($callable);
}
}
else {
$hook = str_replace("-", "_", $command_info['command-hook']);
$result = drush_command_invoke_all($hook . '_complete');
}
if (isset($result['values'])) {
// We add a space following all completes. Eventually there may be some
// items (e.g. comma separated arguments) where we don't add a space.
Expand Down
1 change: 1 addition & 0 deletions includes/preflight.inc
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ function drush_init_application_global_options($container) {

function drush_init_annotation_commands($container) {
$application = $container->get('application');
/** @var \Consolidation\AnnotatedCommand\CommandFileDiscovery */
$discovery = $container->get('commandDiscovery');
$commandFiles = $discovery->discover(DRUSH_BASE_PATH . '/lib/Drush', '\Drush');
drush_init_register_command_files($container, $commandFiles);
Expand Down
59 changes: 59 additions & 0 deletions lib/Drush/CommandFiles/core/BrowseCommands.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
namespace Drush\CommandFiles\core;

class BrowseCommands {

/**
* Display a link to a given path or open link in a browser.
*
* @todo Document new @handle-remote-commands and @bootstrap annotations.
*
* @param string|null $path Path to open. If omitted, the site front page will be opened.
* @option string $browser Specify a particular browser (defaults to operating system default). Use --no-browser to suppress opening a browser.
* @todo conflicts with global option: @option integer $redirect-port The port that the web server is redirected to (e.g. when running within a Vagrant environment).
* @usage drush browse
* Open default web browser (if configured or detected) to the site front page.
* @usage drush browse node/1
* Open web browser to the path node/1.
* @usage drush @example.prod
* Open a browser to the web site specified in a site alias.
* @usage drush browse --browser=firefox admin
* Open Firefox web browser to the path 'admin'.
* @todo not used AFAIK @bootstrap DRUSH_BOOTSTRAP_NONE
* @todo not used @handle-remote-commands true
* @complete \Drush\CommandFiles\core\BrowseCommands::complete
*/
public function browse($path = '', $options = ['browser' => NULL]) {
// Redispatch if called against a remote-host so a browser is started on the
// the *local* machine.
$alias = drush_get_context('DRUSH_TARGET_SITE_ALIAS');
if (drush_sitealias_is_remote_site($alias)) {
$site_record = drush_sitealias_get_record($alias);
$return = drush_invoke_process($site_record, 'browse', func_get_args(), drush_redispatch_get_options(), array('integrate' => TRUE));
if ($return['error_status']) {
return drush_set_error('Unable to execute browse command on remote alias.');
}
else {
$link = $return['object'];
}
}
else {
if (!drush_bootstrap(DRUSH_BOOTSTRAP_DRUPAL_FULL)) {
// Fail gracefully if unable to bootstrap Drupal. drush_bootstrap() has
// already logged an error.
return FALSE;
}
$link = drush_url($path, array('absolute' => TRUE));
}

drush_start_browser($link);
return $link;
}

/*
* An argument provider for shell completion.
*/
static function complete() {
return ['values' => ['admin', 'admin/content', 'admin/reports', 'admin/structure', 'admin/people', 'admin/modules', 'admin/config']];
}
}

0 comments on commit b0a27da

Please sign in to comment.