client: lib_gen: add hledger conf support

This commit is contained in:
2024-07-05 21:24:11 -07:00
parent bbbecff7f1
commit c2ac298f67

View File

@@ -322,7 +322,7 @@ function lib_gen::__gen_container()
lib_utils::print_debug "Generating container"
#
# Check to proceed
# Check to proceed with profile-specific
#
lib_utils::print_custom " \e[32m│\e[0m\n"
@@ -377,7 +377,7 @@ function lib_gen::__gen_container()
lib_utils::print_custom " \e[32m│ │ └─\e[34m Using subprofile:\e[0m ${_subprofile}\n"
#
# Execute
# Execute profile-specific
#
lib_utils::print_custom " \e[32m│ │\e[0m\n"
@@ -394,7 +394,7 @@ function lib_gen::__gen_container()
fi
lib_utils::print_custom " \e[32m│ │\e[0m\n"
lib_utils::print_custom " \e[32m│ ├─\e[34;1m Generate (or update) container hledger-flow configs and/or accounts? [Y/n] \e[0m"
lib_utils::print_custom " \e[32m│ ├─\e[34;1m Generate (or update) hledger configuration file? [Y/n] \e[0m"
read -p "" _read
_confirm="${_read:-y}"
if [[ "$_confirm" == [yY] ]]; then
@@ -403,6 +403,19 @@ function lib_gen::__gen_container()
lib_utils::print_debug "_gen_path=${_gen_path}"
lib_utils::print_debug "_gen_conf_path=${_gen_conf_path}"
lib_gen::__gen_hledger "$_gen_path" "$_gen_conf_path"
fi
lib_utils::print_custom " \e[32m│ │\e[0m\n"
lib_utils::print_custom " \e[32m│ ├─\e[34;1m Generate (or update) container hledger-flow configs and/or accounts? [Y/n] \e[0m"
read -p "" _read
_confirm="${_read:-y}"
if [[ "$_confirm" == [yY] ]]; then
local _gen_path="${DOCKER_FINANCE_CLIENT_FLOW}/profiles/${_profile}/${_subprofile}"
local _gen_conf_path="${_gen_path}/docker-finance.d"
lib_utils::print_debug "_gen_path=${_gen_path}"
lib_utils::print_debug "_gen_conf_path=${_gen_conf_path}"
lib_gen::__gen_flow "$_gen_path" "$_gen_conf_path"
fi
}
@@ -475,6 +488,53 @@ function lib_gen::__gen_shell_write()
"${global_repo_conf_dir}/container/shell/superscript.bash.in" >"$_file"
}
#
# Generate hledger configuration file
#
function lib_gen::__gen_hledger()
{
local -r _gen_path="$1"
local -r _gen_conf_path="$2"
local _dir="${_gen_conf_path}/hledger"
[ ! -d "$_dir" ] && mkdir -p "$_dir"
local _file="${_dir}/hledger.conf"
if [ -f "$_file" ]; then
lib_utils::print_custom " \e[32m│ │ │ └─\e[34m hledger configuration found, backup then generate new one? [Y/n] \e[0m"
read -p "" _read
_confirm="${_read:-y}"
if [[ "$_confirm" == [yY] ]]; then
cp -a "$_file" "${_file}_${global_suffix}" || lib_utils::die_fatal
lib_gen::__gen_hledger_write "$_file"
local _print_custom=" \e[32m│ │ │ └─\e[34m Edit (new) hledger configuration now? [Y/n] \e[0m"
fi
else
lib_gen::__gen_hledger_write "$_file"
local _print_custom=" \e[32m│ │ │ └─\e[34m Edit (new) hledger configuration now? [Y/n] \e[0m"
fi
lib_utils::print_custom "$_print_custom"
read -p "" _read
_confirm="${_read:-y}"
[[ "$_confirm" == [yY] ]] && $EDITOR "$_file"
}
function lib_gen::__gen_hledger_write()
{
local _file="$1"
[ -z "$_file" ] && lib_utils::die_fatal
[ -z "$DOCKER_FINANCE_VERSION" ] && lib_utils::die_fatal
[ -z "$global_repo_conf_dir" ] && lib_utils::die_fatal
sed \
-e "s:@DOCKER_FINANCE_VERSION@:${DOCKER_FINANCE_VERSION}:g" \
"${global_repo_conf_dir}/container/hledger/hledger.conf.in" >"$_file"
}
#
# Generate hledger-flow
#