function setUp()
 {
     // Bootstrap to ensure the Console_Table library is present and included.
     drush_bootstrap(DRUSH_BOOTSTRAP_DRUSH);
     $this->original_columns = drush_get_context('DRUSH_COLUMNS');
     // Some table data we reuse between tests.
     $this->numbers = array(array('1', '12', '123'), array('1234', '12345', '123456'), array('1234567', '12345678', '123456789'));
     $this->words = array(array('Drush is a command line shell', 'scripting interface', 'for Drupal'), array('A veritable', 'Swiss Army knife', 'designed to make life easier for us'));
 }
示例#2
0
/**
 * The main Drush function.
 *
 * - Parses the command line arguments, configuration files and environment.
 * - Prepares and executes a Drupal bootstrap, if possible,
 * - Dispatches the given command.
 *
 * @return
 *   Whatever the given command returns.
 */
function drush_main()
{
    $phases = _drush_bootstrap_phases();
    $completed_phases = array();
    $return = '';
    $command_found = FALSE;
    foreach ($phases as $phase) {
        if (drush_bootstrap($phase)) {
            $completed_phases[$phase] = TRUE;
            $command = drush_parse_command();
            // Process a remote command if 'remote-host' option is set.
            if (drush_remote_command()) {
                $command_found = TRUE;
                break;
            }
            if (is_array($command)) {
                if (array_key_exists($command['bootstrap'], $completed_phases) && empty($command['bootstrap_errors'])) {
                    drush_log(dt("Found command: !command (commandfile=!commandfile)", array('!command' => $command['command'], '!commandfile' => $command['commandfile'])), 'bootstrap');
                    $command_found = TRUE;
                    // Dispatch the command(s).
                    $return = drush_dispatch($command);
                    if (drush_get_context('DRUSH_DEBUG')) {
                        drush_print_timers();
                    }
                    drush_log(dt('Peak memory usage was !peak', array('!peak' => drush_format_size(memory_get_peak_usage()))), 'memory');
                    break;
                }
            }
        } else {
            break;
        }
    }
    if (!$command_found) {
        // If we reach this point, we have not found either a valid or matching command.
        $args = implode(' ', drush_get_arguments());
        if (isset($command) && is_array($command)) {
            foreach ($command['bootstrap_errors'] as $key => $error) {
                drush_set_error($key, $error);
            }
            drush_set_error('DRUSH_COMMAND_NOT_EXECUTABLE', dt("The drush command '!args' could not be executed.", array('!args' => $args)));
        } elseif (!empty($args)) {
            drush_set_error('DRUSH_COMMAND_NOT_FOUND', dt("The drush command '!args' could not be found.", array('!args' => $args)));
        } else {
            // This can occur if we get an error during _drush_bootstrap_drush_validate();
            drush_set_error('DRUSH_COULD_NOT_EXECUTE', dt("Drush could not execute."));
        }
    }
    // We set this context to let the shutdown function know we reached the end of drush_main();
    drush_set_context("DRUSH_EXECUTION_COMPLETED", TRUE);
    // After this point the drush_shutdown function will run,
    // exiting with the correct exit code.
    return $return;
}
示例#3
0
 public function testGetCommands()
 {
     drush_bootstrap(DRUSH_BOOTSTRAP_DRUSH);
     $commands = drush_get_commands();
     $command = $commands['dl'];
     $this->assertEquals('dl', current($command['aliases']));
     $this->assertEquals('download', current($command['deprecated-aliases']));
     $this->assertArrayHasKey('version_control', $command['engines']);
     $this->assertArrayHasKey('package_handler', $command['engines']);
     $this->assertEquals('pm-download', $command['command']);
     $this->assertEquals('pm', $command['commandfile']);
     $this->assertEquals('drush_command', $command['callback']);
     $this->assertArrayHasKey('examples', $command['sections']);
     $this->assertTrue($command['is_alias']);
     $command = $commands['pm-download'];
     $this->assertArrayNotHasKey('is_alias', $command);
 }
示例#4
0
/**
 * The main Drush function.
 *
 * - Parses the command line arguments, configuration files and environment.
 * - Prepares and executes a Drupal bootstrap, if possible,
 * - Dispatches the given command.
 *
 * @return
 *   Whatever the given command returns.
 */
function drush_main()
{
    $phases = _drush_bootstrap_phases();
    foreach ($phases as $phase) {
        drush_bootstrap($phase);
        $command = drush_parse_command();
        if (is_array($command)) {
            if ($command['bootstrap'] == $phase) {
                // Dispatch the command(s).
                // After this point the drush_shutdown function will run,
                // exiting with the correct exit code.
                return drush_dispatch($command);
            }
        }
    }
    // If we reach this point, we have not found a valid command.
    drush_set_error('DRUSH_COMMAND_NOT_FOUND');
}
示例#5
0
/**
 * The main Drush function.
 *
 * - Parses the command line arguments, configuration files and environment.
 * - Prepares and executes a Drupal bootstrap, if possible,
 * - Dispatches the given command.
 *
 * @return
 *   Whatever the given command returns.
 */
function drush_main()
{
    $phases = _drush_bootstrap_phases();
    $return = '';
    $command_found = FALSE;
    foreach ($phases as $phase) {
        if (drush_bootstrap($phase)) {
            $command = drush_parse_command();
            if (is_array($command)) {
                if ($command['bootstrap'] == $phase && empty($command['bootstrap_errors'])) {
                    drush_log(dt("Found command: !command", array('!command' => $command['command'])), 'bootstrap');
                    $command_found = TRUE;
                    // Dispatch the command(s).
                    $return = drush_dispatch($command);
                    drush_log_timers();
                    break;
                }
            }
        } else {
            break;
        }
    }
    if (!$command_found) {
        // If we reach this point, we have not found either a valid or matching command.
        $args = implode(' ', drush_get_arguments());
        $drush_command = array_pop(explode('/', DRUSH_COMMAND));
        if (isset($command) && is_array($command)) {
            foreach ($command['bootstrap_errors'] as $key => $error) {
                drush_set_error($key, $error);
            }
            drush_set_error('DRUSH_COMMAND_NOT_EXECUTABLE', dt("The command '!drush_command !args' could not be executed.", array('!drush_command' => $drush_command, '!args' => $args)));
        } elseif (!empty($args)) {
            drush_set_error('DRUSH_COMMAND_NOT_FOUND', dt("The command '!drush_command !args' could not be found.", array('!drush_command' => $drush_command, '!args' => $args)));
        } else {
            // This can occur if we get an error during _drush_bootstrap_drush_validate();
            drush_set_error('DRUSH_COULD_NOT_EXECUTE', dt("Drush could not execute."));
        }
    }
    // We set this context to let the shutdown function know we reached the end of drush_main();
    drush_set_context("DRUSH_EXECUTION_COMPLETED", TRUE);
    // After this point the drush_shutdown function will run,
    // exiting with the correct exit code.
    return $return;
}
示例#6
0
 /**
  * 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;
 }
示例#7
0
#!/usr/bin/env php
<?php 
// $Id: drush.php,v 1.24.2.4 2008/11/28 17:18:20 adrian Exp $
/**
 * @file
 * drush is a PHP script implementing a command line shell for Drupal.
 *
 * @requires PHP CLI 4.3.0, PHP CLI 5.x, or newer.
 */
define('DRUSH_DRUPAL_BOOTSTRAP', 'includes/bootstrap.inc');
// Terminate immediately unless invoked as a command line script
if (!drush_verify_cli()) {
    die('drush.php is designed to run via the command line.');
}
exit(drush_bootstrap($GLOBALS['argc'], $GLOBALS['argv']));
/**
 * Verify that we are running PHP through the command line interface.
 *
 * This function is useful for making sure that code cannot be run via the web server,
 * such as a function that needs to write files to which the web server should not have
 * access to.
 *
 * @return
 *   A boolean value that is true when PHP is being run through the command line, 
 *   and false if being run through cgi or mod_php.
 */
function drush_verify_cli()
{
    if (php_sapi_name() == 'cgi') {
        return is_numeric($_SERVER['argc']) && $_SERVER['argc'] > 0;
    }
 /**
  * Test various output formats using php-eval with no Drupal site.
  *
  * @dataProvider provider
  **/
 public function testOutputFormat($name, $format, $data, $expected)
 {
     drush_bootstrap(DRUSH_BOOTSTRAP_DRUSH);
     $this->assertEquals($expected, trim(drush_format($data, array(), $format)), $name . ': ' . $format);
 }
 *    'host' => '127.0.0.1',
 *    'port' => '',
 *    'driver' => 'mysql',
 *    'prefix' => 'prefix_',
 *  ),
 * );
 *
 *
 * Usage:
 * drush scr export.php --root=/Users/ortiz/tools/projects/dlts_viewer_distro/builds/viewer --user=1
 */
// We need extra memory
ini_set("memory_limit", "512M");
// http://docs.drush.org/en/master/bootstrap/
// http://api.drush.org/api/drush/includes%21bootstrap.inc/constant/DRUSH_BOOTSTRAP_DRUPAL_FULL/7.x
drush_bootstrap(DRUSH_BOOTSTRAP_DRUPAL_FULL);
function default_commands()
{
    return array(array('label' => t('TEST'), 'callback' => array('test')));
}
function prepare($caller)
{
    global $settings;
    foreach (file_scan_directory(__DIR__ . '/include/', '/.*\\.inc$/') as $include) {
        include_once $include->uri;
    }
    $settings = settings($caller);
    $install_file = $settings['script_path']['dirname'] . '/' . $settings['script_path']['filename'] . '.install';
    $info_file = $settings['script_path']['dirname'] . '/' . $settings['script_path']['filename'] . '.info';
    $includes = file_scan_directory($settings['script_path']['dirname'], '/.*\\.inc$/');
    foreach ($includes as $include) {