forked from EvergreenCrypto/docker-finance
container: root: change base path, related refactor
The base path is now *outside* of the macro directory; allowing for a more integrated view of `dfi`'s entire `root` system. This is more apparent once running an interactive session where the expectation is (more intuitively) that any path should be relative to 'src/root' and not 'src/root/macro'. The rationale for why this was in 'src/root/macro' to begin with stems from how `root` (by default) will automatically load rootlogon.C in the directory that `root` is started. This is causing more confusion than not because `dfi`'s usage of `root` is not limited to macros. These changes skirt the line between needing a major API bump and not but, so far, appears to be on the side of *not*. However, the TODOs noted for macro loading should be addressed prior to any API changes.
This commit is contained in:
@@ -107,17 +107,18 @@ function lib_root::__parse_root()
|
||||
#
|
||||
|
||||
if [[ "$_arg" =~ ^macro ]]; then
|
||||
local -r _macro="$_stub"
|
||||
# TODO: utilize stub when 'repo/' and 'custom/' is implemented (like plugins)
|
||||
local -r _macro="$_arg"
|
||||
|
||||
# Repo macros
|
||||
[ ! -f "${DOCKER_FINANCE_CONTAINER_REPO}/src/root/macro/${_macro}" ] \
|
||||
[ ! -f "${DOCKER_FINANCE_CONTAINER_REPO}/src/root/${_macro}" ] \
|
||||
&& lib_utils::die_fatal "repo macro not found '${_macro}'"
|
||||
|
||||
# TODO: currently, only repo macros are supported
|
||||
# (no custom macros, use custom plugins instead)
|
||||
|
||||
# Per API (v1), requires path stub format
|
||||
declare -gr global_arg_macro="$_stub"
|
||||
declare -gr global_arg_macro="$_macro"
|
||||
fi
|
||||
|
||||
#
|
||||
@@ -149,10 +150,29 @@ function lib_root::__root()
|
||||
{
|
||||
lib_utils::deps_check "root"
|
||||
|
||||
local _exec=("root" "-l")
|
||||
local -r _path="${DOCKER_FINANCE_CONTAINER_REPO}/src/root"
|
||||
pushd "$_path" 1>/dev/null || lib_utils::die_fatal "could not pushd '${_path}'"
|
||||
|
||||
#
|
||||
# Default
|
||||
# Base command
|
||||
#
|
||||
|
||||
# NOTE:
|
||||
#
|
||||
# rootlogon.C *MUST* be loaded at any startup; as if fulfills loading
|
||||
# of `dfi` source files and other library requirements.
|
||||
#
|
||||
# Typically, ROOT.cern would load rootlogon.C if we start `root`
|
||||
# interactively within the macro directory. However, `dfi` has its own
|
||||
# requirements.
|
||||
#
|
||||
# After rootlogon, any loading of macros, plugins or any `dfi` files
|
||||
# can be completed using the `dfi` API.
|
||||
|
||||
local _exec=("root" "-l" "macro/rootlogon.C")
|
||||
|
||||
#
|
||||
# Interactive opts
|
||||
#
|
||||
|
||||
# Start interactive instance w/out loading/running macro or plugin
|
||||
@@ -161,7 +181,7 @@ function lib_root::__root()
|
||||
fi
|
||||
|
||||
#
|
||||
# Macro
|
||||
# Macro: non-interactive opts
|
||||
#
|
||||
|
||||
if [ ! -z "$global_arg_macro" ]; then
|
||||
@@ -179,11 +199,19 @@ function lib_root::__root()
|
||||
#
|
||||
# - run() static function is the entry point for all macros
|
||||
#
|
||||
local -r _file="${global_arg_macro##*/}"
|
||||
local -r _stub="${_file^}"
|
||||
|
||||
local -r _class="${_stub%.*}"
|
||||
local -r _caller="dfi::macro::${global_arg_macro%%/*}::${_class}"
|
||||
# TODO: modify substring when 'repo/' and 'custom/' is implemented (like plugins)
|
||||
|
||||
local _namespace="${global_arg_macro#*/}"
|
||||
_namespace="${_namespace%/*}"
|
||||
declare -r _namespace
|
||||
|
||||
local _class="${global_arg_macro##*/}"
|
||||
_class="${_class^}"
|
||||
_class="${_class%.*}"
|
||||
declare -r _class
|
||||
|
||||
local -r _caller="dfi::macro::${_namespace}::${_class}"
|
||||
|
||||
# Per-API signatures (v1)
|
||||
if [[ ${_class} == "Hash" ]]; then
|
||||
@@ -195,6 +223,7 @@ function lib_root::__root()
|
||||
else
|
||||
_run="run()"
|
||||
fi
|
||||
|
||||
_exec+=("-e" "${_caller}::${_run}")
|
||||
|
||||
# NOTE: when called via shell, server(s) are implied to
|
||||
@@ -205,7 +234,7 @@ function lib_root::__root()
|
||||
fi
|
||||
|
||||
#
|
||||
# Plugin
|
||||
# Plugin: non-interactive opts
|
||||
#
|
||||
|
||||
if [ ! -z "$global_arg_plugin" ]; then
|
||||
@@ -216,19 +245,8 @@ function lib_root::__root()
|
||||
# Execute
|
||||
#
|
||||
|
||||
# NOTE:
|
||||
#
|
||||
# This *MUST* be executed from within the macro directory,
|
||||
# regardless of what is loaded (macro or plugin), as ROOT.cern
|
||||
# will automatically load rootlogon.C (which `dfi` needs).
|
||||
#
|
||||
# Any loading or macros of plugins from within an interactive
|
||||
# instance can use be completed with the `dfi` API.
|
||||
#
|
||||
lib_utils::print_debug "${_exec[@]}"
|
||||
pushd "${DOCKER_FINANCE_CONTAINER_REPO}/src/root/macro" 1>/dev/null \
|
||||
&& "${_exec[@]}" \
|
||||
|| lib_utils::die_fatal "could not pushd"
|
||||
"${_exec[@]}" || lib_utils::die_fatal "root exited with: $?"
|
||||
}
|
||||
|
||||
# vim: sw=2 sts=2 si ai et
|
||||
|
||||
Reference in New Issue
Block a user