diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 4bfbe3a375c4f56a0cdb8bc2e6cb2d07b9589551..fa6a7280c77b1331c0c2f0d01b54b65a5d7672db 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -6,6 +6,7 @@ Libraries x.x-x.x, xxxx-xx-xx Libraries 7.x-1.x, xxxx-xx-xx ----------------------------- +#542940 by tstoeckler, sun: Add libraries-list command. #919632 by tstoeckler: Add example library info file for testing purposes. #719896 by tstoeckler, sun: Documentation clean-up and tests improvement. #542940 by sun: Added initial Drush integration file. diff --git a/libraries.drush.inc b/libraries.drush.inc index f6656abbd9399851e759b3303d0ff6f4e4e4ba53..a8213768953578330dbb52f2eefaec3dc780744f 100644 --- a/libraries.drush.inc +++ b/libraries.drush.inc @@ -10,18 +10,18 @@ * Implements hook_drush_command(). */ function libraries_drush_command() { - return; $items['libraries-list'] = array( 'callback' => 'libraries_drush_list', 'description' => dt('Lists registered library information.'), + 'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_FULL, ); - $items['libraries-download'] = array( + /**$items['libraries-download'] = array( 'callback' => 'libraries_drush_download', 'description' => dt('Downloads a registered library into the libraries directory for the active site.'), 'arguments' => array( 'name' => dt('The internal name of the registered library.'), ), - ); + );*/ return $items; } @@ -40,6 +40,54 @@ See libraries-list for a list of registered libraries.'); } } +/** + * Lists registered library information. + */ +function libraries_drush_list() { + $libraries = libraries_detect(libraries_info()); + ksort($libraries); + + if (empty($libraries)) { + drush_print('There are no registered libraries.'); + } + + else { + $header = array('Name', 'Status', 'Version', 'Variants'); + $rows = array(); + foreach ($libraries as $library_name => $library) { + $version = $library['version']; + if ($library['installed']) { + $status = 'OK'; + } + else { + $status = drupal_ucfirst($library['error']); + $version = (empty($library['version']) ? '-' : $library['version']); + } + if (empty($library['variants'])) { + $variants = '-'; + } + else { + $variants = array(); + foreach ($library['variants'] as $variant_name => $variant) { + if ($variant['installed']) { + $variants[] = $variant_name; + } + } + if (empty($variants)) { + $variants = '-'; + } + else { + $variants = implode(', ', $variants); + } + } + + $rows[] = array($library_name, $status, $version, $variants); + } + $table = new Console_Table(); + drush_print($table->fromArray($header, $rows)); + } +} + /** * Downloads a library. * diff --git a/libraries.module b/libraries.module index 58eab1c5f09bc71456587c5e0328e978e034b945..285c2358642d5d18526ea811e4e58614239e40db 100644 --- a/libraries.module +++ b/libraries.module @@ -260,7 +260,8 @@ function libraries_detect_library(&$library) { $library['library path'] = libraries_get_path($name); } if (!file_exists($library['library path'])) { - $library['error'] = t('%library could not be found.', array('%library' => $library['title'])); + $library['error'] = 'not found'; + $library['error message'] = t('%library could not be found.', array('%library' => $library['title'])); return; } @@ -275,7 +276,8 @@ function libraries_detect_library(&$library) { $library['version'] = $library['version callback']($library, $library['version arguments']); } if (empty($library['version'])) { - $library['error'] = t('The version of %library could not be detected.', array('%library' => $library['title'])); + $library['error'] = 'not detected'; + $library['error message'] = t('The version of %library could not be detected.', array('%library' => $library['title'])); return; } @@ -289,7 +291,8 @@ function libraries_detect_library(&$library) { } } if (!$version) { - $library['error'] = t('The installed version %version of %library is not supported.', array( + $library['error'] = 'not supported'; + $library['error message'] = t('The installed version %version of %library is not supported.', array( '%version' => $library['version'], '%library' => $library['title'], )); @@ -318,7 +321,8 @@ function libraries_detect_library(&$library) { $variant['installed'] = $variant['variant callback']($library, $name, $variant['variant arguments']); } if (empty($variant['installed'])) { - $variant['error'] = t('The %variant variant of %library could not be found.', array( + $variant['error'] = 'not found'; + $variant['error message'] = t('The %variant variant of %library could not be found.', array( '%variant' => $name, '%library' => $library['title'], )); diff --git a/tests/libraries_test.module b/tests/libraries_test.module index c2b5b786045854b9299c96cace63a49dc739fe00..3ec8bd4e51aa287db3b6175a17e69b59f5331760 100644 --- a/tests/libraries_test.module +++ b/tests/libraries_test.module @@ -188,21 +188,6 @@ function libraries_test_libraries_info() { 'variant callback' => '_libraries_test_return_installed', 'variant arguments' => array(TRUE), ), - 'example_variant_2' => array( - 'files' => array( - 'js' => array( - 'example_4.js', - ), - 'css' => array( - 'example_4.css', - ), - 'php' => array( - 'example_4.php', - ), - ), - 'variant callback' => '_libraries_test_return_installed', - 'variant arguments' => array(TRUE), - ), ), );