From b4bae82ae752ce5053fb6a66385ffe88e3f4e29c Mon Sep 17 00:00:00 2001 From: Aaron Fiore Date: Wed, 10 Jul 2024 18:16:53 -0700 Subject: [PATCH] container: lib_edit: refactor for clearer fatal errors - Make known that non-zero returns are fatal errors - Return success on success (iadd | manual) - Add iadd to `edit` usage help - Remove outdated comments --- .../src/finance/lib/internal/lib_edit.bash | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/container/src/finance/lib/internal/lib_edit.bash b/container/src/finance/lib/internal/lib_edit.bash index 5078cda..4e45bd6 100644 --- a/container/src/finance/lib/internal/lib_edit.bash +++ b/container/src/finance/lib/internal/lib_edit.bash @@ -59,7 +59,7 @@ function lib_edit::__parse_args() Configuration type: - type${global_arg_delim_2} + type${global_arg_delim_2} Account: @@ -246,11 +246,13 @@ function lib_edit::__edit() _path+="/post-import.journal" [ ! -f "$_path" ] && touch "$_path" - # TODO: upstream request to provide comment(N) entries - [[ "$_type" == "iadd" ]] && /usr/bin/hledger-iadd -f "$_path" + if [[ "$_type" == "iadd" ]]; then + hledger-iadd -f "$_path" || lib_utils::die_fatal + fi - # TODO: option for editor type - [[ "$_type" == "manual" ]] && $EDITOR "$_path" + if [[ "$_type" == "manual" ]]; then + $EDITOR "$_path" || lib_utils::die_fatal + fi ;; meta) [ -z "$global_conf_meta" ] && lib_utils::die_fatal @@ -271,11 +273,12 @@ function lib_edit::__edit() # - If saved to original, opening with `--skip` will clobber the # original file's comments. local -r _skip="$(grep -E "^//!" $_path | wc -l)" - visidata --quitguard --motd-url file:///dev/null --filetype csv --skip "$_skip" "$_path" + local -r _args=("--quitguard" "--motd-url" "file:///dev/null" "--filetype" "csv" "--skip" "$_skip" "$_path") + visidata "${_args[@]}" || lib_utils::die_fatal # TODO: HACK: visidata saves w/ DOS-style carriage... # ...but there seems to be no option out of this. - sed -i 's:\r::g' "$_path" + sed -i 's:\r::g' "$_path" || lib_utils::die_fatal ;; preprocess | rules) # Run all paths through one editor instance