Skip to content

Instantly share code, notes, and snippets.

@welly
Created November 20, 2017 17:49
Show Gist options
  • Save welly/c1210457dc32f56d8a1c9b23fb451354 to your computer and use it in GitHub Desktop.
Save welly/c1210457dc32f56d8a1c9b23fb451354 to your computer and use it in GitHub Desktop.
fb cli tool for docker4drupal projects
#!/usr/bin/env bash
# Console colors
red='\033[0;91m'
red_bg='\033[101m'
yellow_bg='\033[43m'
green='\033[0;32m'
green_bg='\033[42m'
yellow='\033[1;33m'
NC='\033[0m'
#----------
echo-red () { echo -e "${red}$1${NC}"; }
echo-green () { echo -e "${green}$1${NC}"; }
echo-green-bg () { echo -e "${green_bg}$1${NC}"; }
echo-yellow () { echo -e "${yellow}$1${NC}"; }
echo-warning () {
echo -e "${yellow_bg} WARNING: ${NC} ${yellow}$1${NC}";
shift
for arg in "$@"; do
echo -e " $arg"
done
}
echo-error () {
echo -e "${red_bg} ERROR: ${NC} ${red}$1${NC}"
shift
for arg in "$@"; do
echo -e " $arg"
done
}
echo-alert () {
echo -e "${red_bg} ALERT: ${NC} ${red}$1${NC}"
shift
for arg in "$@"; do
echo -e " $arg"
done
}
# Nicely prints command help
# @param $1 command name
# @param $2 description
# @param $3 [optional] command color
printh ()
{
local COMMAND_COLUMN_WIDTH=25;
case "$3" in
yellow)
printf " ${yellow}%-${COMMAND_COLUMN_WIDTH}s${NC}" "$1"
echo -e " $2"
;;
green)
printf " ${green}%-${COMMAND_COLUMN_WIDTH}s${NC}" "$1"
echo -e " $2"
;;
*)
printf " %-${COMMAND_COLUMN_WIDTH}s" "$1"
echo -e " $2"
;;
esac
}
#----------
_start_containers ()
{
docker-compose up -d --remove-orphans --build
}
_stop_containers ()
{
docker-compose stop
}
_exec ()
{
docker-compose exec $@
}
#---------- Commands
up ()
{
_start_containers
}
stop ()
{
_stop_containers
}
restart ()
{
_stop_containers && _start_containers
}
kill ()
{
docker-compose kill
}
#---------- Command line parameters
case "$1" in
up)
up
;;
stop)
stop
;;
restart)
restart
;;
kill)
kill
;;
exec)
_exec "$@"
;;
drush)
if [[ $1 == "" ]]; then
_exec php drush
else
shift
_exec php drush -r /var/www/html/web "$@"
fi
;;
drupal)
if [[ "$1" == "" ]]; then
_exec php drupal
else
shift
_exec php drupal --root=/var/www/html/web "$@"
fi
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment