diff --git a/drush/database_sanitize.drush8.inc b/drush/database_sanitize.drush8.inc index 590a5ab..e470ad0 100644 --- a/drush/database_sanitize.drush8.inc +++ b/drush/database_sanitize.drush8.inc @@ -46,6 +46,11 @@ function database_sanitize_drush_command() { 'required' => FALSE, ], ], + 'outputformat' => [ + 'default' => 'yaml', + 'output-data-type' => 'format-yaml', + 'pipe-format' => 'json', + ], 'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_FULL, ]; @@ -81,21 +86,33 @@ function database_sanitize_drush_command() { */ function database_sanitize_analyze() { $yml_file_path = drush_get_option('file'); + $machine_readable = drush_get_option('format') || drush_get_context('DRUSH_PIPE'); if ($yml_file_path && !file_exists($yml_file_path)) { return drush_set_error(dt('File does not exist @file', ['@file' => $yml_file_path])); } + $result = FALSE; $missing_tables = \Drupal::service('database_sanitize')->getUnspecifiedTables($yml_file_path); if (!$missing_tables) { - drush_log(dt('All database tables are already specified in sanitize YML files'), 'ok'); - return; + $result = TRUE; + if (!$machine_readable) { + drush_log(dt('All database tables are already specified in sanitize YML files'), 'ok'); + } } - drush_log(dt('There are @count tables not defined on sanitize YML files', ['@count' => count($missing_tables)]), 'warning'); + elseif (!$machine_readable) { + drush_log(dt('There are @count tables not defined on sanitize YML files', ['@count' => count($missing_tables)]), 'warning'); + } if (drush_get_option('list')) { - drush_log(implode("\n", $missing_tables), 'warning'); + return $missing_tables; + } + + if ($machine_readable) { + return [ + 'result' => $result, + ]; } }