container: lib_plugins: add plugins type support
- Adds plugin type support
* Adds pseudo-paths to help usage
* Adds arg parsing of given plugin name
- Prepended pseudo-paths will use repo or custom plugin
This commit is contained in:
@@ -30,7 +30,7 @@ source "${DOCKER_FINANCE_CONTAINER_REPO}/src/finance/lib/internal/lib_utils.bash
|
|||||||
|
|
||||||
function lib_plugins::plugins()
|
function lib_plugins::plugins()
|
||||||
{
|
{
|
||||||
# NOTE: no args to parse, pass directly to plugin
|
lib_plugins::__parse_args "$@"
|
||||||
lib_plugins::__plugins "$@"
|
lib_plugins::__plugins "$@"
|
||||||
lib_utils::catch $?
|
lib_utils::catch $?
|
||||||
}
|
}
|
||||||
@@ -39,34 +39,79 @@ function lib_plugins::plugins()
|
|||||||
# Implementation
|
# Implementation
|
||||||
#
|
#
|
||||||
|
|
||||||
function lib_plugins::__plugins()
|
function lib_plugins::__parse_args()
|
||||||
{
|
{
|
||||||
[ -z "$global_usage" ] && lib_utils::die_fatal
|
#
|
||||||
|
# Expected format:
|
||||||
|
#
|
||||||
|
# $global_usage repo${global_arg_delim_1}file [args]
|
||||||
|
# - Executes plugin in repository
|
||||||
|
#
|
||||||
|
# $global_usage custom${global_arg_delim_1}file [args]
|
||||||
|
# - Executes plugin outside of repository
|
||||||
|
#
|
||||||
|
|
||||||
[ -z "$DOCKER_FINANCE_CONTAINER_FLOW" ] && lib_utils::die_fatal
|
[ -z "$global_usage" ] && lib_utils::die_fatal
|
||||||
local -r _path="${DOCKER_FINANCE_CONTAINER_FLOW}/plugins"
|
[ -z "$global_arg_delim_1" ] && lib_utils::die_fatal
|
||||||
|
|
||||||
|
[ -z "$DOCKER_FINANCE_CONTAINER_REPO" ] && lib_utils::die_fatal
|
||||||
|
local -r _repo="${DOCKER_FINANCE_CONTAINER_REPO}/plugins/finance"
|
||||||
|
[ ! -d "$_repo" ] && lib_utils::die_fatal
|
||||||
|
|
||||||
|
[ -z "$DOCKER_FINANCE_CONTAINER_PLUGINS" ] && lib_utils::die_fatal
|
||||||
|
local -r _custom="${DOCKER_FINANCE_CONTAINER_PLUGINS}/finance"
|
||||||
|
[ ! -d "$_custom" ] && lib_utils::die_fatal
|
||||||
|
|
||||||
local -r _usage="
|
local -r _usage="
|
||||||
\e[32mDescription:\e[0m
|
\e[32mDescription:\e[0m
|
||||||
|
|
||||||
Execute a plugin within the flow plugins path
|
Execute a categorical plugin
|
||||||
|
|
||||||
\e[32mUsage:\e[0m
|
\e[32mUsage:\e[0m
|
||||||
|
|
||||||
$ $global_usage <plugin> [args]
|
$ $global_usage <repo${global_arg_delim_1}plugin | custom${global_arg_delim_1}plugin> [args]
|
||||||
|
|
||||||
\e[32mExamples:\e[0m
|
\e[32mExamples:\e[0m
|
||||||
|
|
||||||
\e[37;2m# Execute a custom plugin in ${_path}\e[0m
|
\e[37;2m# Execute a repository plugin in '${_repo}'\e[0m
|
||||||
$ $global_usage example.bash \"hello\"
|
$ $global_usage repo${global_arg_delim_1}example.bash \"I'm in repo\"
|
||||||
|
|
||||||
|
\e[37;2m# Execute a custom plugin in '${_custom}'\e[0m
|
||||||
|
$ $global_usage custom${global_arg_delim_1}example.bash \"I'm in custom\"
|
||||||
"
|
"
|
||||||
|
|
||||||
if [ "$#" -eq 0 ]; then
|
[ $# -eq 0 ] && lib_utils::die_usage "$_usage"
|
||||||
lib_utils::die_usage "$_usage"
|
|
||||||
|
local -r _arg="$1"
|
||||||
|
|
||||||
|
[[ ! "$_arg" =~ (^repo${global_arg_delim_1}|^custom${global_arg_delim_1}) ]] && lib_utils::die_usage "$_usage"
|
||||||
|
|
||||||
|
local -r _key="${_arg%${global_arg_delim_1}*}"
|
||||||
|
local -r _len="$((${#_key} + 1))"
|
||||||
|
|
||||||
|
if [[ "$_key" =~ ^repo$|^custom$ ]]; then
|
||||||
|
local -r _arg_type="${_arg:${_len}}"
|
||||||
|
[ -z "$_arg_type" ] && lib_utils::die_usage "$_usage"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
exec ${_path}/$*
|
local _path
|
||||||
|
case "$_key" in
|
||||||
|
repo)
|
||||||
|
_path="${_repo}/${_arg_type}"
|
||||||
|
;;
|
||||||
|
custom)
|
||||||
|
_path="${_custom}/${_arg_type}"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
lib_utils::die_usage "$_usage"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
declare -gr global_arg_path="$_path"
|
||||||
|
}
|
||||||
|
|
||||||
|
function lib_plugins::__plugins()
|
||||||
|
{
|
||||||
|
exec $global_arg_path "${@:2}"
|
||||||
return $?
|
return $?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user