forked from EvergreenCrypto/docker-finance
client: lib_gen: new custom plugin layout, update example plugin
- Generates new custom plugin directory layout upon `gen`
* Allows for drop-in client-side/container-side custom plugins
- Moved container plugin example into container's plugins
* Plugin is no longer generated upon `gen` (it's available in-repo)
- Updates plugin example
- Provides requisite lib_finance initialization
- Refactored, added more checks
- Expand example case
- Linter fixes
This commit is contained in:
@@ -416,6 +416,17 @@ function lib_gen::__gen_container()
|
||||
{
|
||||
lib_utils::print_debug "Generating container"
|
||||
|
||||
#
|
||||
# Generate plugins (custom)
|
||||
#
|
||||
|
||||
[ -z "$DOCKER_FINANCE_CLIENT_PLUGINS" ] && lib_utils::die_fatal
|
||||
if [ ! -d "$DOCKER_FINANCE_CLIENT_PLUGINS" ]; then
|
||||
mkdir -p "$DOCKER_FINANCE_CLIENT_PLUGINS" || lib_utils::die_fatal
|
||||
fi
|
||||
|
||||
lib_gen::__gen_plugins
|
||||
|
||||
#
|
||||
# Generate flow
|
||||
#
|
||||
@@ -431,16 +442,40 @@ function lib_gen::__gen_container()
|
||||
fi
|
||||
|
||||
[ -z "$DOCKER_FINANCE_CLIENT_FLOW" ] && lib_utils::die_fatal
|
||||
|
||||
if [ ! -d "$DOCKER_FINANCE_CLIENT_FLOW" ]; then
|
||||
mkdir -p "$DOCKER_FINANCE_CLIENT_FLOW" || lib_utils::die_fatal
|
||||
fi
|
||||
|
||||
lib_gen::__gen_times
|
||||
lib_gen::__gen_plugins
|
||||
lib_gen::__gen_profile
|
||||
}
|
||||
|
||||
#
|
||||
# Generate plugins (custom):
|
||||
#
|
||||
# - Provides:
|
||||
# - A layout to drop-in custom plugins
|
||||
# * Underlying impl expects this layout
|
||||
#
|
||||
|
||||
function lib_gen::__gen_plugins()
|
||||
{
|
||||
lib_utils::print_debug "Generating custom plugins layout"
|
||||
|
||||
local -r _client="${DOCKER_FINANCE_CLIENT_PLUGINS}/client"
|
||||
if [ ! -d "${_client}/docker" ]; then
|
||||
mkdir -p "${_client}/docker" || lib_utils::die_fatal
|
||||
fi
|
||||
|
||||
local -r _container="${DOCKER_FINANCE_CLIENT_PLUGINS}/container"
|
||||
if [ ! -d "${_container}/finance" ]; then
|
||||
mkdir -p "${_container}/finance" || lib_utils::die_fatal
|
||||
fi
|
||||
if [ ! -d "${_container}/root" ]; then
|
||||
mkdir -p "${_container}/root" || lib_utils::die_fatal
|
||||
fi
|
||||
}
|
||||
|
||||
#
|
||||
# Generate flow: times
|
||||
#
|
||||
@@ -461,81 +496,6 @@ function lib_gen::__gen_times()
|
||||
# NOTE: timew database will be created upon first call
|
||||
}
|
||||
|
||||
#
|
||||
# Generate flow: plugins
|
||||
#
|
||||
# - Provides a place to drop-in any custom plugin
|
||||
# - Provides a default example plugin
|
||||
#
|
||||
|
||||
function lib_gen::__gen_plugins()
|
||||
{
|
||||
lib_utils::print_debug "Generating plugins"
|
||||
|
||||
local -r _plugins="${DOCKER_FINANCE_CLIENT_FLOW}/plugins"
|
||||
if [ ! -d "$_plugins" ]; then
|
||||
mkdir -p "$_plugins" || lib_utils::die_fatal
|
||||
fi
|
||||
|
||||
local -r _example="${_plugins}/example.bash"
|
||||
|
||||
if [ -f "$_example" ]; then
|
||||
lib_utils::print_debug "Example plugin found, overwriting: '${_example}'"
|
||||
fi
|
||||
|
||||
echo "#!/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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
#
|
||||
# Plugins
|
||||
#
|
||||
# The plugins path (this directory) is where you can place any executable.
|
||||
#
|
||||
# Any plugin found in this directory will be made available via the \`plugins\` command.
|
||||
# As such, your plugin will have access to all global variables provided by finance.bash
|
||||
#
|
||||
# The following is an example of how to create your own plugin:
|
||||
#
|
||||
|
||||
echo -e \"
|
||||
This container's environment:
|
||||
|
||||
\$(printenv | grep ^DOCKER_FINANCE)
|
||||
|
||||
This plugin's caller profile:
|
||||
|
||||
\${global_parent_profile}\${global_arg_delim_1}\${global_child_profile}
|
||||
|
||||
This plugin's path is:
|
||||
|
||||
\$0
|
||||
|
||||
This plugin's arguments:
|
||||
|
||||
'\${@}'
|
||||
\"
|
||||
|
||||
# vim: sw=2 sts=2 si ai et" >"$_example"
|
||||
|
||||
chmod +x "$_example" || lib_utils::die_fatal
|
||||
}
|
||||
|
||||
#
|
||||
# Generate flow: profile/subprofile
|
||||
#
|
||||
|
||||
77
container/plugins/finance/example.bash
Executable file
77
container/plugins/finance/example.bash
Executable file
@@ -0,0 +1,77 @@
|
||||
#!/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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
#
|
||||
# Plugins
|
||||
#
|
||||
# The plugins path (this directory) is where you can place any executable.
|
||||
# Any plugin found in this directory will be made available via the `plugins` command.
|
||||
#
|
||||
# Your plugin will have access to globals and functions provided by:
|
||||
#
|
||||
# - finance.bash
|
||||
# - lib_finance.bash
|
||||
#
|
||||
# The following is an example of how to create your own plugin:
|
||||
#
|
||||
|
||||
#
|
||||
# "Libraries"
|
||||
#
|
||||
|
||||
[ -z "$DOCKER_FINANCE_CONTAINER_REPO" ] && exit 1
|
||||
source "${DOCKER_FINANCE_CONTAINER_REPO}/src/finance/lib/lib_finance.bash"
|
||||
|
||||
# Initialize "constructor"
|
||||
[[ -z "$global_parent_profile" || -z "$global_arg_delim_1" || -z "$global_child_profile" ]] && exit 1
|
||||
lib_finance::finance "${global_parent_profile}${global_arg_delim_1}${global_child_profile}"
|
||||
|
||||
#
|
||||
# Implementation
|
||||
#
|
||||
|
||||
function main()
|
||||
{
|
||||
echo -e "
|
||||
This container's environment:
|
||||
|
||||
$(printenv | grep ^DOCKER_FINANCE | sort)
|
||||
|
||||
This plugin's caller profile:
|
||||
|
||||
${global_parent_profile}${global_arg_delim_1}${global_child_profile}
|
||||
|
||||
This plugin's path is:
|
||||
|
||||
$0
|
||||
|
||||
This plugin's arguments:
|
||||
|
||||
'${*}'
|
||||
|
||||
Showing total current BTC balance:
|
||||
"
|
||||
echo -n " "
|
||||
lib_finance::ledger bal assets liabilities cur:BTC | tail -n1
|
||||
echo
|
||||
}
|
||||
|
||||
main "$@"
|
||||
|
||||
# vim: sw=2 sts=2 si ai et
|
||||
Reference in New Issue
Block a user