Skip to content

Commit

Permalink
Issue #220: Adding drush_chalk().
Browse files Browse the repository at this point in the history
  • Loading branch information
serundeputy authored Apr 11, 2020
2 parents 3a48077 + 9c9e6fc commit 7a632aa
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ before_install:
- git clone https://github.com/drush-ops/drush /home/travis/web/drush
- cd /home/travis/web/drush && git checkout 8.x && composer install
- sudo ln -s /home/travis/web/drush/drush /usr/local/bin/drush
- cp -a /home/travis/build/backdrop-contrib/drush /home/travis/web/drush/commands/backdrop
- cp -a /home/travis/build/backdrop-contrib/backdrop-drush-extension /home/travis/web/drush/commands/backdrop
- mysql -e "drop database if exists backdrop"
- mysql -e "create database backdrop"
- cd /home/travis/web
Expand Down
17 changes: 17 additions & 0 deletions backdrop.drush.inc
Original file line number Diff line number Diff line change
Expand Up @@ -196,3 +196,20 @@ function system_module_implements_alter(&$implementations, $hook) {
$implementations = array_diff_key($implementations, array('system' => NULL));
}
}

/**
* Drush chalk lets you format output text for color, bold, etc.
*
* @param string $output
* The string of text you wish to format.
* @param string $color
* The color or format you wish to use ie. '32m' for green.
*
* @return string
* The formatted string.
*/
function drush_chalk(string $output, string $color) {
$output = "\033[$color$output\033[0m";

return $output;
}
20 changes: 15 additions & 5 deletions commands/pm/backdrop_pm_enable.drush.inc
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,16 @@ function backdrop_command_pm_enable() {
}

$projects_list = implode(', ', $projects);
$projects_list = drush_chalk($projects_list, '1m');
$proceed = drush_confirm(
"The following projects will be enabled: $projects_list.
Do you want to enable the projects?"
);

if (!$proceed) {
$cancelled = drush_chalk('Cancelled', '33m');
drush_print_r(
dt("\n\t\e[033mCancelled\e[0m $projects_list not enabled.\n")
dt("\n\t$cancelled: $projects_list not enabled.\n")
);
}
else {
Expand Down Expand Up @@ -100,7 +102,9 @@ function _enable_project($project, $module_list) {
$project_exists = backdrop_command_pm_enable_validate($project, $module_list);
// If the $project directory does not exist then gracefully fail.
if (!$project_exists) {
drush_print_r("\n\t\e[031mError\e[0m $project does not exist in your Backdrop installation.");
$error = drush_chalk('Error', '31m');
$project = drush_chalk($project, '1m');
drush_print_r("\n\t$error $project does not exist in your Backdrop installation.");
drush_print_r("\tTry downloading $project first with the command: drush dl $project\n");
return FALSE;
}
Expand All @@ -111,17 +115,23 @@ function _enable_project($project, $module_list) {
$module = $query->execute()->fetchAssoc();

if ($module['status']) {
$failed = drush_chalk('Failed', '31m');
$module_name = drush_chalk($module['name'], '1m');
drush_print_r(
"\n\t\e[31m Failed\e[0m to enable module " . $module['name'] . ": it is already enabled.\n"
"\n\t$failed to enable module $module_name: it is already enabled.\n"
);
return FALSE;
}

if (module_enable(array($project), FALSE)) {
drush_print_r("\n\t\e[32mSuccess\e[0m: module $project enabled.\n");
$success = drush_chalk('Sucess', '32m');
$project = drush_chalk($project, '1m');
drush_print_r("\n\t$success: module $project enabled.\n");
return TRUE;
}
drush_print_r("\n\t\e[31mFailed\e[0m to enable module " . $project);
$failed = drush_chalk('Failed', '31m');
$project = drush_chalk($project, '1m');
drush_print_r("\n\t$failed: to enable module " . $project);
return FALSE;
}

Expand Down

0 comments on commit 7a632aa

Please sign in to comment.