Skip to content

Commit

Permalink
Add --strict=2: force an error if there are 'warning' log messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
greg-1-anderson committed Nov 9, 2014
1 parent 9d16f31 commit bcadd5a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
6 changes: 6 additions & 0 deletions drush.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ function drush_main() {
}
drush_postflight();

// How strict are we? If we are very strict, turn 'ok' into 'error'
// if there are any warnings in the log.
if (($return == 0) && (drush_get_option('strict') > 1) && drush_log_has_errors()) {
$return = 1;
}

// After this point the drush_shutdown function will run,
// exiting with the correct exit code.
return $return;
Expand Down
12 changes: 11 additions & 1 deletion includes/drush.inc
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ function drush_get_global_options($brief = FALSE) {
$options['remote-os'] = array('hidden' => TRUE, 'description' => 'The operating system used on the remote host. Managed by site alias.');
$options['site-list'] = array('hidden' => TRUE, 'description' => 'List of sites to run commands on. Managed by site alias.');
$options['reserve-margin'] = array('hidden' => TRUE, 'description' => 'Remove columns from formatted opions. Managed by multi-site command handling.');
$options['strict'] = array('propagate' => TRUE, 'hidden' => TRUE, 'description' => 'Check requirements more strictly / remove backwards-compatibility features for unit tests.');
$options['strict'] = array('propagate' => TRUE, 'description' => 'Return an error on unrecognized options. --strict=0: Allow unrecognized options. --strict=2: Also return an error on any "warning" log messages. Optional. Default is 1.');
$options['command-specific'] = array('hidden' => TRUE, 'merge-associative' => TRUE, 'description' => 'Command-specific options.');
$options['site-aliases'] = array('hidden' => TRUE, 'merge-associative' => TRUE, 'description' => 'List of site aliases.');
$options['shell-aliases'] = array('hidden' => TRUE, 'merge' => TRUE, 'never-propagate' => TRUE, 'description' => 'List of shell aliases.');
Expand Down Expand Up @@ -1432,6 +1432,16 @@ function drush_log($message, $type = 'notice', $error = null) {
return $callback($entry);
}

function drush_log_has_errors($types = array('warning', 'error', 'failed')) {
$log =& drush_get_context('DRUSH_LOG', array());
foreach ($log as $entry) {
if (in_array($entry['type'], $types)) {
return TRUE;
}
}
return FALSE;
}

/**
* Backend command callback. Add a log message to the log history.
*
Expand Down

0 comments on commit bcadd5a

Please sign in to comment.