browse.drush.inc

  1. 8.0.x commands/core/browse.drush.inc
  2. 6.x commands/core/browse.drush.inc
  3. 7.x commands/core/browse.drush.inc

Functions

Namesort descending Description
browse_drush_command Implements hook_drush_command().
drush_browse Command callback.

File

commands/core/browse.drush.inc
View source
  1. <?php
  2. /**
  3. * Implements hook_drush_command().
  4. */
  5. function browse_drush_command() {
  6. $items = array();
  7. $items['browse'] = array(
  8. 'description' => 'Display a link to a given path or open link in a browser.',
  9. 'bootstrap' => DRUSH_BOOTSTRAP_NONE,
  10. 'handle-remote-commands' => TRUE,
  11. 'arguments' => array(
  12. 'path' => 'Path to open. If omitted, the site front page will be opened.',
  13. ),
  14. 'options' => array(
  15. 'browser' => 'Specify a particular browser (defaults to operating system default). Use --no-brower to suppress opening a browser.',
  16. 'redirect-port' => 'The port that the web server is redirected to (e.g. when running within a Vagrant environment)',
  17. ),
  18. 'examples' => array(
  19. 'drush browse' => 'Open default web browser (if configured or detected) to the site front page.',
  20. 'drush browse node/1' => 'Open web browser to the path node/1.',
  21. 'drush @example.prod' => 'Open a browser to the web site specified in a site alias.',
  22. 'drush browse --browser=firefox admin' => 'Open Firefox web browser to the path \'admin\'.',
  23. ),
  24. );
  25. return $items;
  26. }
  27. /**
  28. * Command callback.
  29. */
  30. function drush_browse($path = '') {
  31. // Redispatch if called against a remote-host so a browser is started on the
  32. // the *local* machine.
  33. $alias = drush_get_context('DRUSH_TARGET_SITE_ALIAS');
  34. if (drush_sitealias_is_remote_site($alias)) {
  35. $site_record = drush_sitealias_get_record($alias);
  36. $return = drush_invoke_process($site_record, 'browse', func_get_args(), drush_redispatch_get_options(), array('integrate' => TRUE));
  37. if ($return['error_status']) {
  38. return drush_set_error('Unable to execute browse command on remote alias.');
  39. }
  40. else {
  41. $link = $return['object'];
  42. }
  43. }
  44. else {
  45. if (!drush_bootstrap(DRUSH_BOOTSTRAP_DRUPAL_FULL)) {
  46. // Fail gracefully if unable to bootstrap Drupal. drush_bootstrap() has
  47. // already logged an error.
  48. return FALSE;
  49. }
  50. $link = drush_url($path, array('absolute' => TRUE));
  51. }
  52. drush_start_browser($link);
  53. return $link;
  54. }