forked from EvergreenCrypto/docker-finance
Merge pull request #145 into master
dae2572client: docker-finance.d: hledger: add docker-finance version tag (Aaron Fiore)4759d10client: docker-finance.d: hledger: remove comment (Aaron Fiore)7d4a843client: docker-finance.d: hledger: remove web args (Aaron Fiore)5acbbfbcontainer: src: lib_hledger: remove hledger version test (Aaron Fiore)a9e1ee3client: docker-finance.d: subscript: remove hledger default args (Aaron Fiore)da8488econtainer: src: lib_hledger: fork hledger-web, log print (Aaron Fiore)8a8395econtainer: src: lib_hledger: pass hledger-{ui,web} args (Aaron Fiore)ba29352client: subscript: remove `ledger` in place of `hledger` (Aaron Fiore)ea392eccontainer: remove `ledger` in place of `hledger` (Aaron Fiore)1101fc8container: rename `lib_ledger` to `lib_hledger` (Aaron Fiore)
This commit is contained in:
@@ -15,15 +15,16 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
# docker-finance @DOCKER_FINANCE_VERSION@
|
||||
|
||||
# NOTE:
|
||||
# - File is treated as a plain configuration file (non-executable)
|
||||
# - Only functional for `hledger 1.34.99-gcf0c7c2ef-20240702` or later
|
||||
# - See sample: https://github.com/simonmichael/hledger/blob/master/hledger.conf.sample
|
||||
|
||||
[balance] not:desc:balances not:equity:balances not:archive
|
||||
[print] not:desc:balances not:equity:balances not:archive
|
||||
|
||||
[ui] assets liabilities not:desc:balances not:equity:balances not:archive
|
||||
[web] --serve --host=0.0.0.0 --base-url http://127.0.0.1:5000 --capabilities=view assets liabilities not:desc:balances not:equity:balances not:archive
|
||||
[web] assets liabilities not:desc:balances not:equity:balances not:archive
|
||||
|
||||
# vim: syn=bash sw=2 sts=2 si ai et
|
||||
|
||||
@@ -25,38 +25,25 @@
|
||||
|
||||
[ -z "$DOCKER_FINANCE_CONTAINER_CMD" ] && echo "DOCKER_FINANCE_CONTAINER_CMD not set, check installation" >&2
|
||||
|
||||
# NOTE: hledger-based commands ending in `\`: the escape is needed so you can add more arguments as needed
|
||||
# TODO: remove default 'not:' arguments to `hledger{-ui,-web}` once distributions support hledger 1.34.99-gcf0c7c2ef-20240702 or higher (--conf support)
|
||||
|
||||
# CLI hledger
|
||||
alias @DOCKER_FINANCE_SUBPROFILE@_hledger='$DOCKER_FINANCE_CONTAINER_CMD @DOCKER_FINANCE_PROFILE@/@DOCKER_FINANCE_SUBPROFILE@ hledger'
|
||||
alias @DOCKER_FINANCE_SUBPROFILE@_ledger='@DOCKER_FINANCE_SUBPROFILE@_hledger'
|
||||
|
||||
# Note: command ends in `\` and newline so you can add more arguments as needed
|
||||
alias @DOCKER_FINANCE_SUBPROFILE@_bal='$DOCKER_FINANCE_CONTAINER_CMD @DOCKER_FINANCE_PROFILE@/@DOCKER_FINANCE_SUBPROFILE@ hledger bal \
|
||||
assets liabilities \
|
||||
not:desc:balances\$ not:equity:balances\$ not:archive \
|
||||
'
|
||||
|
||||
# Terminal UI
|
||||
alias @DOCKER_FINANCE_SUBPROFILE@_ui='$DOCKER_FINANCE_CONTAINER_CMD @DOCKER_FINANCE_PROFILE@/@DOCKER_FINANCE_SUBPROFILE@ hledger-ui -w \
|
||||
assets liabilities \
|
||||
not:desc:balances\$ not:equity:balances\$ not:archive \
|
||||
'
|
||||
alias @DOCKER_FINANCE_SUBPROFILE@_ui='$DOCKER_FINANCE_CONTAINER_CMD @DOCKER_FINANCE_PROFILE@/@DOCKER_FINANCE_SUBPROFILE@ hledger-ui'
|
||||
alias @DOCKER_FINANCE_SUBPROFILE@_hledger-ui='@DOCKER_FINANCE_SUBPROFILE@_ui'
|
||||
alias @DOCKER_FINANCE_SUBPROFILE@_ledger-ui='@DOCKER_FINANCE_SUBPROFILE@_ui'
|
||||
|
||||
# Terminal UI (visidata)
|
||||
alias @DOCKER_FINANCE_SUBPROFILE@_vui='$DOCKER_FINANCE_CONTAINER_CMD @DOCKER_FINANCE_PROFILE@/@DOCKER_FINANCE_SUBPROFILE@ hledger-vui'
|
||||
alias @DOCKER_FINANCE_SUBPROFILE@_hledger-vui='@DOCKER_FINANCE_SUBPROFILE@_vui'
|
||||
alias @DOCKER_FINANCE_SUBPROFILE@_ledger-vui='@DOCKER_FINANCE_SUBPROFILE@_vui'
|
||||
|
||||
# Web UI
|
||||
alias @DOCKER_FINANCE_SUBPROFILE@_web='$DOCKER_FINANCE_CONTAINER_CMD @DOCKER_FINANCE_PROFILE@/@DOCKER_FINANCE_SUBPROFILE@ hledger-web --serve --host=0.0.0.0 --base-url http://127.0.0.1:5000 --allow=view \
|
||||
assets liabilities \
|
||||
not:desc:balances\$ not:equity:balances\$ not:archive \
|
||||
'
|
||||
alias @DOCKER_FINANCE_SUBPROFILE@_web='$DOCKER_FINANCE_CONTAINER_CMD @DOCKER_FINANCE_PROFILE@/@DOCKER_FINANCE_SUBPROFILE@ hledger-web \'
|
||||
alias @DOCKER_FINANCE_SUBPROFILE@_hledger-web='@DOCKER_FINANCE_SUBPROFILE@_web'
|
||||
alias @DOCKER_FINANCE_SUBPROFILE@_ledger-web='@DOCKER_FINANCE_SUBPROFILE@_web'
|
||||
|
||||
# Fetches, imports, generates taxes and reports (using defaults)
|
||||
alias @DOCKER_FINANCE_SUBPROFILE@_all='$DOCKER_FINANCE_CONTAINER_CMD @DOCKER_FINANCE_PROFILE@/@DOCKER_FINANCE_SUBPROFILE@ all'
|
||||
|
||||
@@ -70,7 +70,7 @@ This plugin's arguments:
|
||||
|
||||
Showing total current BTC balance:
|
||||
|
||||
$(lib_finance::ledger bal assets liabilities cur:BTC | tail -n1)
|
||||
$(lib_finance::hledger bal assets liabilities cur:BTC | tail -n1)
|
||||
|
||||
"
|
||||
lib_utils::print_custom "$_example"
|
||||
|
||||
@@ -31,7 +31,7 @@ function docker-finance::completion()
|
||||
mapfile -t _profiles < <(pushd "${DOCKER_FINANCE_CONTAINER_FLOW}"/profiles &>/dev/null && ls -d */*)
|
||||
declare -r _profiles
|
||||
|
||||
local -r _commands=("all" "edit" "fetch" "hledger" "hledger-ui" "hledger-vui" "hledger-web" "import" "ledger" "ledger-ui" "ledger-vui" "ledger-web" "meta" "plugins" "reports" "root" "taxes" "times")
|
||||
local -r _commands=("all" "edit" "fetch" "hledger" "hledger-ui" "hledger-vui" "hledger-web" "import" "meta" "plugins" "reports" "root" "taxes" "times")
|
||||
|
||||
local _reply
|
||||
|
||||
@@ -66,7 +66,7 @@ function docker-finance::completion()
|
||||
import)
|
||||
mapfile -t _reply < <(compgen -W "help year${global_arg_delim_2}" -- "$_cur")
|
||||
;;
|
||||
hledger | ledger)
|
||||
hledger)
|
||||
#
|
||||
# Commands (as described in v1.40)
|
||||
#
|
||||
@@ -95,13 +95,13 @@ function docker-finance::completion()
|
||||
|
||||
mapfile -t _reply < <(compgen -W "${_hledger[*]}" -- "$_cur")
|
||||
;;
|
||||
hledger-ui | ledger-ui)
|
||||
hledger-ui)
|
||||
mapfile -t _reply < <(compgen -W "-h" -- "$_cur")
|
||||
;;
|
||||
hledger-vui | ledger-vui)
|
||||
hledger-vui)
|
||||
mapfile -t _reply < <(compgen -W "-h" -- "$_cur")
|
||||
;;
|
||||
hledger-web | ledger-web)
|
||||
hledger-web)
|
||||
mapfile -t _reply < <(compgen -W "-h" -- "$_cur")
|
||||
;;
|
||||
meta)
|
||||
|
||||
@@ -113,17 +113,17 @@ function main()
|
||||
import)
|
||||
lib_finance::import "${@:3}"
|
||||
;;
|
||||
hledger | ledger)
|
||||
lib_finance::ledger "${@:3}"
|
||||
hledger)
|
||||
lib_finance::hledger "${@:3}"
|
||||
;;
|
||||
hledger-ui | ledger-ui)
|
||||
lib_finance::ledger-ui "${@:3}"
|
||||
hledger-ui)
|
||||
lib_finance::hledger-ui "${@:3}"
|
||||
;;
|
||||
hledger-vui | ledger-vui)
|
||||
lib_finance::ledger-vui "${@:3}"
|
||||
hledger-vui)
|
||||
lib_finance::hledger-vui "${@:3}"
|
||||
;;
|
||||
hledger-web | ledger-web)
|
||||
lib_finance::ledger-web "${@:3}"
|
||||
hledger-web)
|
||||
lib_finance::hledger-web "${@:3}"
|
||||
;;
|
||||
meta)
|
||||
lib_finance::meta "${@:3}"
|
||||
|
||||
@@ -28,38 +28,38 @@ source "${DOCKER_FINANCE_CONTAINER_REPO}/src/finance/lib/internal/lib_utils.bash
|
||||
# Facade
|
||||
#
|
||||
|
||||
function lib_ledger::ledger-import()
|
||||
function lib_hledger::hledger-import()
|
||||
{
|
||||
lib_ledger::__ledger "$@"
|
||||
lib_ledger::__ledger-import "$@"
|
||||
lib_hledger::__hledger "$@"
|
||||
lib_hledger::__hledger-import "$@"
|
||||
lib_utils::catch $?
|
||||
}
|
||||
|
||||
function lib_ledger::ledger-cli()
|
||||
function lib_hledger::hledger-cli()
|
||||
{
|
||||
lib_ledger::__ledger "$@"
|
||||
lib_ledger::__ledger-cli "$@"
|
||||
lib_hledger::__hledger "$@"
|
||||
lib_hledger::__hledger-cli "$@"
|
||||
lib_utils::catch $?
|
||||
}
|
||||
|
||||
function lib_ledger::ledger-ui()
|
||||
function lib_hledger::hledger-ui()
|
||||
{
|
||||
lib_ledger::__ledger "$@"
|
||||
lib_ledger::__ledger-ui "$@"
|
||||
lib_hledger::__hledger "$@"
|
||||
lib_hledger::__hledger-ui "$@"
|
||||
lib_utils::catch $?
|
||||
}
|
||||
|
||||
function lib_ledger::ledger-vui()
|
||||
function lib_hledger::hledger-vui()
|
||||
{
|
||||
lib_ledger::__ledger "$@"
|
||||
lib_ledger::__ledger-vui "$@"
|
||||
lib_hledger::__hledger "$@"
|
||||
lib_hledger::__hledger-vui "$@"
|
||||
lib_utils::catch $?
|
||||
}
|
||||
|
||||
function lib_ledger::ledger-web()
|
||||
function lib_hledger::hledger-web()
|
||||
{
|
||||
lib_ledger::__ledger "$@"
|
||||
lib_ledger::__ledger-web "$@"
|
||||
lib_hledger::__hledger "$@"
|
||||
lib_hledger::__hledger-web "$@"
|
||||
lib_utils::catch $?
|
||||
}
|
||||
|
||||
@@ -68,36 +68,17 @@ function lib_ledger::ledger-web()
|
||||
#
|
||||
|
||||
# Constructor
|
||||
function lib_ledger::__ledger()
|
||||
function lib_hledger::__hledger()
|
||||
{
|
||||
# Base arguments to hledger before end-user added
|
||||
# Base arguments to hledger suite before end-user added
|
||||
[ -z "$global_conf_hledger" ] && lib_utils::die_fatal
|
||||
[ -z "$global_child_profile_journal" ] && lib_utils::die_fatal
|
||||
declare -g global_base_args=("-f" "$global_child_profile_journal")
|
||||
|
||||
#
|
||||
# Apply features to given hledger version.
|
||||
#
|
||||
# CLI version formats:
|
||||
#
|
||||
# hledger 1.34, linux-x86_64
|
||||
# hledger 1.34.99-gcf0c7c2ef-20240702, linux-x86_64
|
||||
#
|
||||
|
||||
# TODO: remove now that 1.40 is guaranteed minimum
|
||||
# 1.34.99 and above
|
||||
hledger --version \
|
||||
| gawk '{ if ($2 !~ /^1.3(4.99|([5-9][\.[0-99]?))/) { exit 1 } }' FS=' '
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
# --conf is supported
|
||||
[ -z "$global_conf_hledger" ] && lib_utils::die_fatal
|
||||
global_base_args+=("--conf" "$global_conf_hledger")
|
||||
fi
|
||||
|
||||
declare -g global_base_args=("--conf" "$global_conf_hledger" "-f" "$global_child_profile_journal")
|
||||
lib_utils::print_debug "${global_base_args[*]}" "$@"
|
||||
}
|
||||
|
||||
function lib_ledger::__parse_ledger-import()
|
||||
function lib_hledger::__parse_hledger-import()
|
||||
{
|
||||
[ -z "$global_usage" ] && lib_utils::die_fatal
|
||||
[ -z "$global_arg_delim_1" ] && lib_utils::die_fatal
|
||||
@@ -157,30 +138,30 @@ function lib_ledger::__parse_ledger-import()
|
||||
fi
|
||||
}
|
||||
|
||||
function lib_ledger::__ledger-import()
|
||||
function lib_hledger::__hledger-import()
|
||||
{
|
||||
lib_ledger::__parse_ledger-import "$@"
|
||||
lib_hledger::__parse_hledger-import "$@"
|
||||
|
||||
time hledger-flow import \
|
||||
"$(dirname $global_child_profile_journal)" \
|
||||
--start-year "$global_arg_year"
|
||||
}
|
||||
|
||||
function lib_ledger::__ledger-cli()
|
||||
function lib_hledger::__hledger-cli()
|
||||
{
|
||||
[ -z "${global_base_args[*]}" ] && lib_utils::die_fatal
|
||||
|
||||
hledger "${global_base_args[@]}" "$@"
|
||||
}
|
||||
|
||||
function lib_ledger::__ledger-ui()
|
||||
function lib_hledger::__hledger-ui()
|
||||
{
|
||||
[ -z "${global_base_args[*]}" ] && lib_utils::die_fatal
|
||||
|
||||
hledger-ui "${global_base_args[@]}" "$@"
|
||||
hledger-ui "${global_base_args[@]}" -w "$@"
|
||||
}
|
||||
|
||||
function lib_ledger::__ledger-vui()
|
||||
function lib_hledger::__hledger-vui()
|
||||
{
|
||||
[ -z "${global_base_args[*]}" ] && lib_utils::die_fatal
|
||||
|
||||
@@ -188,11 +169,24 @@ function lib_ledger::__ledger-vui()
|
||||
| visidata --motd-url file:///dev/null --filetype csv
|
||||
}
|
||||
|
||||
function lib_ledger::__ledger-web()
|
||||
function lib_hledger::__hledger-web()
|
||||
{
|
||||
[ -z "${global_base_args[*]}" ] && lib_utils::die_fatal
|
||||
|
||||
hledger-web "${global_base_args[@]}" "$@"
|
||||
local -r _url="http://127.0.0.1:5000"
|
||||
|
||||
hledger-web "${global_base_args[@]}" \
|
||||
--serve --host=0.0.0.0 --base-url "$_url" --allow=view "$@" 1>/dev/null &
|
||||
|
||||
local -r _pid=$!
|
||||
sleep 3s
|
||||
|
||||
if ! ps -p "$_pid" 1>/dev/null; then
|
||||
lib_utils::print_error "hledger-web failed. See above error message"
|
||||
else
|
||||
lib_utils::print_info "hledger-web started (PID ${_pid}). Point web browser to $_url"
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
# vim: sw=2 sts=2 si ai et
|
||||
@@ -85,7 +85,7 @@ function lib_finance::finance()
|
||||
# Implementation "libraries" (requires previously set globals)
|
||||
source "${DOCKER_FINANCE_CONTAINER_REPO}/src/finance/lib/internal/lib_edit.bash" || exit 1
|
||||
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_hledger.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
|
||||
@@ -173,31 +173,31 @@ function lib_finance::fetch()
|
||||
|
||||
function lib_finance::import()
|
||||
{
|
||||
lib_ledger::ledger-import "$@"
|
||||
lib_hledger::hledger-import "$@"
|
||||
lib_utils::catch $?
|
||||
}
|
||||
|
||||
function lib_finance::ledger()
|
||||
function lib_finance::hledger()
|
||||
{
|
||||
lib_ledger::ledger-cli "$@"
|
||||
lib_hledger::hledger-cli "$@"
|
||||
lib_utils::catch $?
|
||||
}
|
||||
|
||||
function lib_finance::ledger-ui()
|
||||
function lib_finance::hledger-ui()
|
||||
{
|
||||
lib_ledger::ledger-ui "$@"
|
||||
lib_hledger::hledger-ui "$@"
|
||||
lib_utils::catch $?
|
||||
}
|
||||
|
||||
function lib_finance::ledger-vui()
|
||||
function lib_finance::hledger-vui()
|
||||
{
|
||||
lib_ledger::ledger-vui "$@"
|
||||
lib_hledger::hledger-vui "$@"
|
||||
lib_utils::catch $?
|
||||
}
|
||||
|
||||
function lib_finance::ledger-web()
|
||||
function lib_finance::hledger-web()
|
||||
{
|
||||
lib_ledger::ledger-web "$@"
|
||||
lib_hledger::hledger-web "$@"
|
||||
lib_utils::catch $?
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user