Commit 33bcf472 authored by Tobias Stoeckler's avatar Tobias Stoeckler

#542940 by tstoeckler, sun: Add libraries-list command

parent c365e82b
......@@ -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.
......
......@@ -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.
*
......
......@@ -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'],
));
......
......@@ -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),
),
),
);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment