client: lib_docker: add 'type' arg to version
- Add `version` types (client | container | short | all) - Related refactoring
This commit is contained in:
@@ -563,31 +563,96 @@ function lib_docker::__edit()
|
|||||||
$EDITOR "${_paths[@]}"
|
$EDITOR "${_paths[@]}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function lib_docker::__parse_args_version()
|
||||||
|
{
|
||||||
|
[ -z "$global_usage" ] && lib_utils::die_fatal
|
||||||
|
[ -z "$global_arg_delim_1" ] && lib_utils::die_fatal
|
||||||
|
[ -z "$global_arg_delim_2" ] && lib_utils::die_fatal
|
||||||
|
[ -z "$global_arg_delim_3" ] && lib_utils::die_fatal
|
||||||
|
|
||||||
|
local -r _usage="
|
||||||
|
\e[32mDescription:\e[0m
|
||||||
|
|
||||||
|
Print version information
|
||||||
|
|
||||||
|
\e[32mUsage:\e[0m
|
||||||
|
|
||||||
|
$ $global_usage type${global_arg_delim_2}<type>
|
||||||
|
|
||||||
|
\e[32mArguments:\e[0m
|
||||||
|
|
||||||
|
Version type:
|
||||||
|
|
||||||
|
type${global_arg_delim_2}<client|container|short|all>
|
||||||
|
|
||||||
|
\e[32mExamples:\e[0m
|
||||||
|
|
||||||
|
\e[37;2m# Print docker-finance client dependency versions\e[0m
|
||||||
|
$ $global_usage type${global_arg_delim_2}client
|
||||||
|
|
||||||
|
\e[37;2m# Print docker-finance container dependency versions\e[0m
|
||||||
|
$ $global_usage type${global_arg_delim_2}container
|
||||||
|
|
||||||
|
\e[37;2m# Print only docker-finance version\e[0m
|
||||||
|
$ $global_usage type${global_arg_delim_2}short
|
||||||
|
|
||||||
|
\e[37;2m# Print both docker-finance and client dependency versions\e[0m
|
||||||
|
$ $global_usage type${global_arg_delim_2}client${global_arg_delim_3}short
|
||||||
|
|
||||||
|
\e[37;2m# Print docker-finance version and all client/container dependency versions\e[0m
|
||||||
|
$ $global_usage type${global_arg_delim_2}all
|
||||||
|
"
|
||||||
|
|
||||||
|
[ $# -eq 0 ] && lib_utils::die_usage "$_usage"
|
||||||
|
|
||||||
|
for _arg in "$@"; do
|
||||||
|
[[ ! "$_arg" =~ ^type[s]?${global_arg_delim_2} ]] \
|
||||||
|
&& lib_utils::die_usage "$_usage"
|
||||||
|
done
|
||||||
|
|
||||||
|
# Parse key for value
|
||||||
|
for _arg in "$@"; do
|
||||||
|
|
||||||
|
local _key="${_arg%${global_arg_delim_2}*}"
|
||||||
|
local _len="$((${#_key} + 1))"
|
||||||
|
|
||||||
|
if [[ "$_key" =~ ^type[s]?$ ]]; then
|
||||||
|
local _arg_type="${_arg:${_len}}"
|
||||||
|
[ -z "$_arg_type" ] && lib_utils::die_usage "$_usage"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
IFS="$global_arg_delim_3"
|
||||||
|
|
||||||
|
# Arg: type
|
||||||
|
read -ra _read <<<"$_arg_type"
|
||||||
|
for _arg in "${_read[@]}"; do
|
||||||
|
if [[ ! "$_arg" =~ ^client$|^container$|^short$|^all$ ]]; then
|
||||||
|
lib_utils::die_usage "$_usage"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [[ "${_read[*]}" =~ all ]]; then # Note: not anchored
|
||||||
|
declare -gr global_arg_type=("client" "container" "short")
|
||||||
|
else
|
||||||
|
declare -gr global_arg_type=("${_read[@]}")
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
function lib_docker::__version()
|
function lib_docker::__version()
|
||||||
{
|
{
|
||||||
|
lib_docker::__parse_args_version "$@"
|
||||||
|
|
||||||
[ -z "${DOCKER_FINANCE_VERSION}" ] && lib_utils::die_fatal
|
[ -z "${DOCKER_FINANCE_VERSION}" ] && lib_utils::die_fatal
|
||||||
[ -z "${DOCKER_FINANCE_CLIENT_REPO}" ] && lib_utils::die_fatal
|
[ -z "${DOCKER_FINANCE_CLIENT_REPO}" ] && lib_utils::die_fatal
|
||||||
|
|
||||||
#
|
[ -z "${global_arg_type[*]}" ] && lib_utils::die_fatal
|
||||||
# `docker-finance` version
|
|
||||||
#
|
|
||||||
|
|
||||||
local _hash
|
for _type in "${global_arg_type[@]}"; do
|
||||||
if pushd "$DOCKER_FINANCE_CLIENT_REPO" 1>/dev/null; then
|
|
||||||
_hash="$(git log --pretty='format:%h' -n 1)"
|
|
||||||
popd 1>/dev/null || lib_utils::die_fatal
|
|
||||||
else
|
|
||||||
lib_utils::die_fatal
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo
|
case "$_type" in
|
||||||
echo -e "docker-finance v${DOCKER_FINANCE_VERSION} | commit: $_hash"
|
|
||||||
echo -e "───────────────────────────────────────"
|
|
||||||
|
|
||||||
#
|
|
||||||
# Client dependencies
|
|
||||||
#
|
|
||||||
|
|
||||||
|
client)
|
||||||
echo
|
echo
|
||||||
echo "client.system:"
|
echo "client.system:"
|
||||||
|
|
||||||
@@ -603,19 +668,17 @@ function lib_docker::__version()
|
|||||||
| while read _line; do
|
| while read _line; do
|
||||||
echo -e \\t"${_line}"
|
echo -e \\t"${_line}"
|
||||||
done
|
done
|
||||||
|
;;
|
||||||
|
|
||||||
#
|
container)
|
||||||
# Container dependencies
|
|
||||||
#
|
|
||||||
|
|
||||||
[ -z "$global_platform" ] && lib_utils::die_fatal
|
[ -z "$global_platform" ] && lib_utils::die_fatal
|
||||||
|
|
||||||
# Feed dependency manifest (client is not bind-mounted for security reasons)
|
# Feed dependency manifest (client is not bind-mounted for security reasons)
|
||||||
local _manifest
|
local _manifest
|
||||||
_manifest="$(<${DOCKER_FINANCE_CLIENT_REPO}/client/docker-finance.yaml)"
|
_manifest="$(<${DOCKER_FINANCE_CLIENT_REPO}/client/docker-finance.yaml)"
|
||||||
|
|
||||||
case "$global_platform" in
|
|
||||||
# NOTE: uses variable "callback"
|
# NOTE: uses variable "callback"
|
||||||
|
case "$global_platform" in
|
||||||
archlinux)
|
archlinux)
|
||||||
_platform="$global_platform"
|
_platform="$global_platform"
|
||||||
_image="finance"
|
_image="finance"
|
||||||
@@ -649,8 +712,26 @@ function lib_docker::__version()
|
|||||||
done
|
done
|
||||||
done
|
done
|
||||||
echo"
|
echo"
|
||||||
|
;;
|
||||||
|
|
||||||
return $?
|
short)
|
||||||
|
local _hash
|
||||||
|
if pushd "$DOCKER_FINANCE_CLIENT_REPO" 1>/dev/null; then
|
||||||
|
_hash="$(git log --pretty='format:%h' -n 1)"
|
||||||
|
popd 1>/dev/null || lib_utils::die_fatal
|
||||||
|
else
|
||||||
|
lib_utils::die_fatal
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo
|
||||||
|
echo -e "docker-finance v${DOCKER_FINANCE_VERSION} | commit: $_hash"
|
||||||
|
;;
|
||||||
|
|
||||||
|
*)
|
||||||
|
lib_utils::die_fatal "unsupported type"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
# vim: sw=2 sts=2 si ai et
|
# vim: sw=2 sts=2 si ai et
|
||||||
|
|||||||
Reference in New Issue
Block a user