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_DRUSH,
  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). Set to 0 to suppress opening a browser.',
  16. ),
  17. 'examples' => array(
  18. 'drush browse' => 'Open default web browser (if configured or detected) to the site front page.',
  19. 'drush browse node/1' => 'Open web browser to the path node/1.',
  20. 'drush @example.prod' => 'Open a browser to the web site specified in a site alias.',
  21. 'drush browse --browser=firefox admin' => 'Open Firefox web browser to the path \'admin\'.',
  22. ),
  23. );
  24. return $items;
  25. }
  26. /**
  27. * Command callback.
  28. */
  29. function drush_browse($path = '') {
  30. // Redispatch if called against a remote-host so a browser is started on the
  31. // the *local* machine.
  32. $alias = drush_get_context('DRUSH_TARGET_SITE_ALIAS');
  33. if (drush_sitealias_is_remote_site($alias)) {
  34. $site_record = drush_sitealias_get_record($alias);
  35. $return = drush_invoke_process($site_record, 'browse', func_get_args(), drush_redispatch_get_options(), array('integrate' => TRUE));
  36. if ($return['error_status']) {
  37. return drush_set_error('Unable to execute site browse.');
  38. }
  39. else {
  40. $link = $return['object'];
  41. }
  42. }
  43. else {
  44. if (!drush_bootstrap(DRUSH_BOOTSTRAP_DRUPAL_FULL)) {
  45. // Fail gracefully if unable to bootstrap Drupal. drush_bootstrap() has
  46. // already logged an error.
  47. return FALSE;
  48. }
  49. $link = url($path, array('absolute' => TRUE));
  50. }
  51. drush_start_browser($link);
  52. return $link;
  53. }