From a4f9b401d3bbde8a27998f3e6e1b51cc810ff86e Mon Sep 17 00:00:00 2001 From: Aaron Fiore Date: Wed, 7 Aug 2024 23:29:55 -0700 Subject: [PATCH] container: bash: add plugins support / lib_plugins - Executes plugins within profile/subprofile context * Hooks into the container's global environment --- container/src/finance/finance.bash | 4 + .../src/finance/lib/internal/lib_plugins.bash | 73 +++++++++++++++++++ container/src/finance/lib/lib_finance.bash | 7 ++ 3 files changed, 84 insertions(+) create mode 100644 container/src/finance/lib/internal/lib_plugins.bash diff --git a/container/src/finance/finance.bash b/container/src/finance/finance.bash index e889c1e..324a413 100755 --- a/container/src/finance/finance.bash +++ b/container/src/finance/finance.bash @@ -58,6 +58,7 @@ function main() ledger-ui \e[34;3mStart terminal UI (hledger-ui)\e[0m ledger-web \e[34;3mStart web-based UI (hledger-web)\e[0m meta \e[34;3mSearch local financial metadata\e[0m + plugins \e[34;3mExecute given plugin available in plugins' path\e[0m reports \e[34;3mGenerate balance sheet, income statement, etc.\e[0m root \e[34;3mRun ROOT.cern instance for docker-finance analysis\e[0m taxes \e[34;3mGenerate tax reports\e[0m @@ -122,6 +123,9 @@ function main() meta) lib_finance::meta "${@:3}" ;; + plugins) + lib_finance::plugins "${@:3}" + ;; reports) lib_finance::reports "${@:3}" ;; diff --git a/container/src/finance/lib/internal/lib_plugins.bash b/container/src/finance/lib/internal/lib_plugins.bash new file mode 100644 index 0000000..9fe3c52 --- /dev/null +++ b/container/src/finance/lib/internal/lib_plugins.bash @@ -0,0 +1,73 @@ +#!/usr/bin/env bash + +# docker-finance | modern accounting for the power-user +# +# Copyright (C) 2024 Aaron Fiore (Founder, Evergreen Crypto LLC) +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation either version 3 of the License or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not see . + +# +# "Libraries" +# + +[ -z "$DOCKER_FINANCE_CONTAINER_REPO" ] && exit 1 +source "${DOCKER_FINANCE_CONTAINER_REPO}/src/finance/lib/internal/lib_utils.bash" || exit 1 + +# +# Facade +# + +function lib_plugins::plugins() +{ + # NOTE: no args to parse, pass directly to plugin + lib_plugins::__plugins "$@" + lib_utils::catch $? +} + +# +# Implementation +# + +function lib_plugins::__plugins() +{ + [ -z "$global_usage" ] && lib_utils::die_fatal + + [ -z "$DOCKER_FINANCE_CONTAINER_FLOW" ] && lib_utils::die_fatal + local -r _path="${DOCKER_FINANCE_CONTAINER_FLOW}/plugins" + + local -r _usage=" +\e[32mDescription:\e[0m + + Execute a plugin within the flow plugins path + +\e[32mUsage:\e[0m + + $ $global_usage [args] + +\e[32mExamples:\e[0m + + \e[37;2m# Execute a custom plugin in ${_path}\e[0m + $ $global_usage example.bash \"hello\" +" + + if [ "$#" -eq 0 ]; then + lib_utils::die_usage "$_usage" + fi + + exec ${_path}/$* + + return $? +} + +# vim: sw=2 sts=2 si ai et diff --git a/container/src/finance/lib/lib_finance.bash b/container/src/finance/lib/lib_finance.bash index 5f80c71..3ffb83a 100644 --- a/container/src/finance/lib/lib_finance.bash +++ b/container/src/finance/lib/lib_finance.bash @@ -87,6 +87,7 @@ function lib_finance::finance() source "${DOCKER_FINANCE_CONTAINER_REPO}/src/finance/lib/internal/lib_fetch.bash" || exit 1 source "${DOCKER_FINANCE_CONTAINER_REPO}/src/finance/lib/internal/lib_ledger.bash" || exit 1 source "${DOCKER_FINANCE_CONTAINER_REPO}/src/finance/lib/internal/lib_meta.bash" || exit 1 + source "${DOCKER_FINANCE_CONTAINER_REPO}/src/finance/lib/internal/lib_plugins.bash" || exit 1 source "${DOCKER_FINANCE_CONTAINER_REPO}/src/finance/lib/internal/lib_reports.bash" || exit 1 source "${DOCKER_FINANCE_CONTAINER_REPO}/src/finance/lib/internal/lib_taxes.bash" || exit 1 } @@ -199,6 +200,12 @@ function lib_finance::ledger-web() lib_utils::catch $? } +function lib_finance::plugins() +{ + lib_plugins::plugins "$@" + lib_utils::catch $? +} + function lib_finance::reports() { lib_reports::reports "$@"