Browse Source

new: correctly implement the arguments pass-through to docker-compose.

raw-remaining-args
Valentin Lab 9 years ago
parent
commit
c0020f82a9
  1. 50
      bin/compose

50
bin/compose

@ -1649,15 +1649,16 @@ _setup_state_dir() {
trap_add EXIT "rm -rf \"$state_tmpdir\"" trap_add EXIT "rm -rf \"$state_tmpdir\""
} }
## Returns arg list of an docker-compose
get_docker_compose_opts_list() { get_docker_compose_opts_list() {
local cache_file="$state_tmpdir/$FUNCNAME.cache.$(echo "$*" | md5_compat)"
local cache_file="$CACHEDIR/$FUNCNAME.cache.$(cat "$(which docker-compose)" | md5_compat)"
if [ -e "$cache_file" ]; then if [ -e "$cache_file" ]; then
debug "$FUNCNAME: cache hit ($*)"
# debug "$FUNCNAME: cache hit ($*)"
cat "$cache_file" cat "$cache_file"
return 0 return 0
fi fi
docker-compose "$@" --help | grep '^Options:' -A 20000 |
docker_compose_help_msg=$(docker-compose "$@" --help 2>/dev/null) || return 1
echo "$docker_compose_help_msg" | grep '^Options:' -A 20000 |
tail -n +2 | tail -n +2 |
egrep "^\s+-" | egrep "^\s+-" |
sed -r 's/\s+((((-[a-zA-Z]|--[a-zA-Z0-9-]+)( [A-Z=]+|=[^ ]+)?)(, )?)+)\s+.*$/\1/g' | sed -r 's/\s+((((-[a-zA-Z]|--[a-zA-Z0-9-]+)( [A-Z=]+|=[^ ]+)?)(, )?)+)\s+.*$/\1/g' |
@ -1668,14 +1669,14 @@ _MULTIOPTION_REGEX='^((-[a-zA-Z]|--[a-zA-Z0-9-]+)(, )?)+'
_MULTIOPTION_REGEX_LINE_FILTER=$_MULTIOPTION_REGEX'(\s|=)' _MULTIOPTION_REGEX_LINE_FILTER=$_MULTIOPTION_REGEX'(\s|=)'
get_docker_compose_multi_opts_list() { get_docker_compose_multi_opts_list() {
opts_list=$(get_docker_compose_opts_list "$@")
opts_list=$(get_docker_compose_opts_list "$@") || return 1
echo "$opts_list" | egrep "$_MULTIOPTION_REGEX_LINE_FILTER" | echo "$opts_list" | egrep "$_MULTIOPTION_REGEX_LINE_FILTER" |
sed -r "s/^($_MULTIOPTION_REGEX)(\s|=).*$/\1/g" | sed -r "s/^($_MULTIOPTION_REGEX)(\s|=).*$/\1/g" |
tr ',' "\n" | xargs echo tr ',' "\n" | xargs echo
} }
get_docker_compose_single_opts_list() { get_docker_compose_single_opts_list() {
opts_list=$(get_docker_compose_opts_list "$@")
opts_list=$(get_docker_compose_opts_list "$@") || return 1
echo "$opts_list" | egrep -v "$_MULTIOPTION_REGEX_LINE_FILTER" | echo "$opts_list" | egrep -v "$_MULTIOPTION_REGEX_LINE_FILTER" |
tr ',' "\n" | xargs echo tr ',' "\n" | xargs echo
} }
@ -1691,6 +1692,15 @@ clean_cache() {
fi fi
} }
str_matches() {
local str="$1"
shift
for pattern in "$@"; do
eval "[[ \"$str\" == $pattern ]]" && return 0
done
return 1
}
[ "$SOURCED" ] && return 0 [ "$SOURCED" ] && return 0
@ -1722,8 +1732,9 @@ no_hooks=
no_init= no_init=
action= action=
stage="main" ## switches from 'main', to 'action', 'remainder' stage="main" ## switches from 'main', to 'action', 'remainder'
# DC_MATCH_MULTI=
# DC_MATCH_SINGLE=
is_docker_compose_action=
DC_MATCH_MULTI=
DC_MATCH_SINGLE=
while [ "$#" != 0 ]; do while [ "$#" != 0 ]; do
case "$stage" in case "$stage" in
"main") "main")
@ -1764,8 +1775,10 @@ while [ "$#" != 0 ]; do
*) *)
action="$1" action="$1"
stage="action" stage="action"
# DC_MATCH_MULTI=$(get_docker_compose_multi_opts_list "$action") || return 1
# DC_MATCH_SINGLE="$(get_docker_compose_single_opts_list "$action") $(echo "$DC_MATCH_MULTI" | sed -r 's/( |$)/=\* /g')"
DC_MATCH_MULTI=$(get_docker_compose_multi_opts_list "$action") &&
DC_MATCH_SINGLE="$(get_docker_compose_single_opts_list "$action") $(echo "$DC_MATCH_MULTI" | sed -r 's/( |$)/=\* /g')" &&
is_docker_compose_action=true
;; ;;
esac esac
;; ;;
@ -1775,12 +1788,19 @@ while [ "$#" != 0 ]; do
no_init=true ; no_hooks=true ; no_relations=true no_init=true ; no_hooks=true ; no_relations=true
action_opts+=("$1") action_opts+=("$1")
;; ;;
--verbose|-v)
export VERBOSE=true
action_opts+=("$1")
;;
--*|-*) --*|-*)
action_opts+=("$1")
if [ "$is_docker_compose_action" ]; then
if str_matches "$1" DC_MATCH_MULTI; then
action_opts=("$1" "$2")
shift;
elif str_matches "$1" DC_MATCH_SINGLE; then
action_opts=("$1")
else
err "Unknown option '$1'. Please check help."
docker-compose "$action" --help >&2
exit 1
fi
fi
;; ;;
*) *)
action_posargs+=("$1") action_posargs+=("$1")

Loading…
Cancel
Save