diff --git a/commands/core/views.drush.inc b/commands/core/views.drush.inc index 76476bb..865bcc5 100644 --- a/commands/core/views.drush.inc +++ b/commands/core/views.drush.inc @@ -17,12 +17,6 @@ function views_drush_help($section) { return dt('Views commands'); case 'meta:views:summary': return dt('Views drush commands.'); - case 'drush:views-list': - return dt('Show a list of available views with information about them.'); - case 'drush:views-enable': - return dt('Enable the specified views. Follow the command with a space delimited list of view names'); - case 'drush:views-disable': - return dt('Disable the specified views. Follow the command with a space delimited list of view names'); } } @@ -47,17 +41,20 @@ function views_drush_command() { 'name' => array( 'description' => 'A string contained in the view\'s name to filter the results with.', 'example-value' => 'node', - 'value' => 'optional', + 'value' => 'required', ), 'tags' => array( 'description' => 'A comma-separated list of views tags by which to filter the results.', 'example-value' => 'default', - 'value' => 'optional', + 'value' => 'required', ), 'status' => array( 'description' => 'Status of the views by which to filter the results. Choices: enabled, disabled.', - 'example-value' => 'enable', - 'value' => 'optional', + 'example-value' => 'enabled', + 'value' => 'required', + ), + 'format' => array( + 'description' => 'Define the output format. Known formats are: json, print_r, and export.', ), ), 'examples' => array( @@ -72,6 +69,11 @@ function views_drush_command() { 'drupal dependencies' => array('views', 'views_ui'), 'description' => 'Get a list of all Views analyze warnings', 'aliases' => array('va'), + 'options' => array( + 'format' => array( + 'description' => 'Define the output format. Known formats are: json, print_r, and export.', + ), + ), ); $items['views-enable'] = array( @@ -154,6 +156,8 @@ function drush_views_list() { $disabled_views = array(); $enabled_views = array(); + $format = drush_get_option('format', FALSE); + $views = views_get_all_views(); // Get the --name option. @@ -244,20 +248,28 @@ function drush_views_list() { drush_print($summary . ":\n"); } - // Print all rows as a table. + // Return all rows or print as a table. if (count($enabled_views) || count($disabled_views)) { $rows = array_merge($enabled_views, $disabled_views); - $total = count($rows); - // Put the headers as first row. - array_unshift($rows, $header); - drush_print_table($rows, TRUE); + if ($format) { + $output = drush_format($rows, $format); + drush_print($output); + return $output; + } + else { + $total = count($rows); + // Put the headers as first row. + array_unshift($rows, $header); + + drush_print_table($rows, TRUE); - // Print the summary messages. - drush_print(dt('A total of @total views were found in this Drupal installation:', array('@total' => $total))); - drush_print(' ' . dt('@dis views are disabled', array('@dis' => $disabled)) . "\n"); + // Print the summary messages. + drush_print(dt('A total of @total views were found in this Drupal installation:', array('@total' => $total))); + drush_print(' ' . dt('@dis views are disabled', array('@dis' => $disabled)) . "\n"); - return $rows; + return $rows; + } } else { drush_set_error(dt('No views found.')); @@ -269,8 +281,11 @@ function drush_views_list() { * Drush views analyze command. */ function drush_views_analyze() { + $messages = NULL; $messages_count = 0; + $format = drush_get_option('format', FALSE); + $views = views_get_all_views(); if (!empty($views)) { @@ -279,14 +294,23 @@ function drush_views_analyze() { $view = $view->getExecutable(); $analyzer->setView($view); if ($messages = $analyzer->getMessages($view)) { - drush_print($view_name); - foreach ($messages as $message) { - $messages_count++; - drush_print($message['type'] .': '. $message['message'], 2); + if ($format) { + $output = drush_format($messages, $format); + drush_print($output); + return $output; + } + else { + drush_print($view_name); + foreach ($messages as $message) { + $messages_count++; + drush_print($message['type'] .': '. $message['message'], 2); + } } } } - return drush_log(dt('A total of @total views were analyzed and @messages problems were found.', array('@total' => count($views), '@messages' => $messages_count)), 'ok'); + + drush_log(dt('A total of @total views were analyzed and @messages problems were found.', array('@total' => count($views), '@messages' => $messages_count)), 'ok'); + return $messages; } else { return drush_set_error(dt('There are no views to analyze')); @@ -298,10 +322,6 @@ function drush_views_analyze() { */ function drush_views_enable() { $view_names = func_get_args(); - // Return early if no view names were specified. - if (empty($view_names)) { - return drush_set_error(dt('Please specify a list of view names to enable')); - } _views_drush_op('enable', $view_names); } @@ -310,10 +330,6 @@ function drush_views_enable() { */ function drush_views_disable() { $view_names = func_get_args(); - // Return early if no view names were specified. - if (empty($view_names)) { - return drush_set_error(dt('Please specify a list of view names to disable')); - } _views_drush_op('disable', $view_names); }