Skip to content

Commit

Permalink
Merge pull request #3 from taurthil/develop
Browse files Browse the repository at this point in the history
add new functions ip, mysql, mysqldump
  • Loading branch information
lukaszolszewski authored Nov 8, 2017
2 parents b83aa04 + 7784299 commit 826224c
Showing 1 changed file with 42 additions and 15 deletions.
57 changes: 42 additions & 15 deletions mage2docker.plugin.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ _mage2docker_mage() {
docker exec -it -u www-data $1 bin/magento $2
}

_mage2docker_container_ip() {
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $1
}

_mage2docker_report() {
compadd `docker exec -u www-data $1 ls -tr var/report`
}
Expand All @@ -22,23 +26,32 @@ _mage2docker_log(){
compadd `docker exec -u www-data $1 ls -tr var/log`
}

_mage2docker() {
_mage2docker_mysql_data() {
printf '%s ' 'User name:'
read user
printf '%s ' 'Database name:'
read database
printf '%s ' 'file name:'
read file
}

_mage2docker() {

local curcontext="$curcontext" state line
typeset -A opt_args

_arguments \
'1: :->containerName'\
'2: :->command' \
'3: :->options'

case $state in
containerName)
compadd $(_docker_get_container_name)
;;
command)
compadd "$@" bash-www bash logs magento mage mage-cache mage-reindex mage-di mage-upgrade mage-report mage-log grunt watch rename rm restart stop inspect top
;;
compadd "$@" bash-www bash logs magento mage mage-cache mage-reindex mage-di mage-upgrade mage-report mage-log grunt watch rename rm restart stop inspect top mysqldump mysql ip
;;
options)
case $words[3] in
mage)
Expand All @@ -49,7 +62,7 @@ _mage2docker() {
;;
mage-log)
_mage2docker_log $words[2]
;;
;;
esac
esac
}
Expand All @@ -62,9 +75,9 @@ mage2docker () {
docker $2 $1
;;
logs)
docker logs -f $1
docker logs -f $1
;;
bash)
bash)
docker exec -it -u root $1 bash
;;
bash-www)
Expand All @@ -74,10 +87,10 @@ mage2docker () {
docker exec -it -u www-data $1 bin/magento
;;
mage)$
_mage2docker_mage $1 $3
_mage2docker_mage $1 $3
;;
mage-cache)
_mage2docker_mage $1 cache:clean
_mage2docker_mage $1 cache:clean
;;
mage-reindex)
_mage2docker_mage $1 indexer:reindex
Expand All @@ -103,22 +116,36 @@ mage2docker () {
mage-log)
docker exec -it -u www-data $1 tail -f var/log/$3
;;
#new informations
ip)
_mage2docker_container_ip $1
;;
mysqldump)
_mage2docker_mysql_data
mysqldump -h$(_mage2docker_container_ip $1) -u$user -p $database > $file
echo "Success database backup was created"
;;
mysql)
_mage2docker_mysql_data
mysql -h$(_mage2docker_container_ip $1) -u$user -p $database < $file
echo "Success database restore"
;;
*)
if [ ! "$1" ]; then
docker ps
else
docker exec -it -u www-data $1 bash
fi
;;
esac
fi
;;
esac

}

if type "docker" > /dev/null; then

compdef _mage2docker mage2docker
alias m2d='mage2docker'

else
else
echo "mage2docker - docker is not installed"
fi

0 comments on commit 826224c

Please sign in to comment.