Created
July 9, 2020 09:29
-
-
Save azat/740ec398eb749311188b4f4fb175a4c0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function array_exist() | |
{ | |
local needle="$1" | |
shift | |
local i | |
for i; do | |
[ "$needle" = "$i" ] && return 0 || continue | |
done | |
return 1 | |
} | |
# Provides new action "oneshot" = "run" + "down" | |
function docker-compose() | |
{ | |
local compose_args=() | |
local action_args=() | |
local action | |
# everything except this, has as argument | |
# (sync with docker-compose --help) | |
local compose_flags=( | |
--verbose | |
--no-ansi | |
--tls | |
--tlsverify | |
--skip-hostname-check | |
--compatibility | |
-v --version | |
) | |
local args=("$@") | |
for ((i = 0; i < $#; ++i)); do | |
local arg="${args[i]}" | |
if [[ -n $action ]]; then | |
action_args+=("$arg") | |
continue | |
fi | |
if [[ ${arg:0:1} != "-" ]]; then | |
action="$arg" | |
else | |
compose_args+=("$arg") | |
if ! array_exist "$arg" "${compose_flags[@]}"; then | |
# skip next argument too | |
(( ++i )) | |
arg="${args[i]}" | |
compose_args+=("$arg") | |
fi | |
fi | |
done | |
case "$action" in | |
oneshot) | |
command docker-compose "${compose_args[@]}" run "${action_args[@]}" && \ | |
command docker-compose "${compose_args[@]}" down --volumes --remove-orphans | |
;; | |
*) | |
command docker-compose "$@";; | |
esac | |
} | |
export -f docker-compose |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment