forked from EvergreenCrypto/docker-finance
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
This commit is contained in:
@@ -59,7 +59,7 @@ function lib_edit::__parse_args()
|
|||||||
|
|
||||||
Configuration type:
|
Configuration type:
|
||||||
|
|
||||||
type${global_arg_delim_2}<fetch|hledger|manual|meta|shell|rules|preprocess>
|
type${global_arg_delim_2}<fetch|hledger|iadd|manual|meta|shell|rules|preprocess>
|
||||||
|
|
||||||
Account:
|
Account:
|
||||||
|
|
||||||
@@ -246,11 +246,13 @@ function lib_edit::__edit()
|
|||||||
_path+="/post-import.journal"
|
_path+="/post-import.journal"
|
||||||
[ ! -f "$_path" ] && touch "$_path"
|
[ ! -f "$_path" ] && touch "$_path"
|
||||||
|
|
||||||
# TODO: upstream request to provide comment(N) entries
|
if [[ "$_type" == "iadd" ]]; then
|
||||||
[[ "$_type" == "iadd" ]] && /usr/bin/hledger-iadd -f "$_path"
|
hledger-iadd -f "$_path" || lib_utils::die_fatal
|
||||||
|
fi
|
||||||
|
|
||||||
# TODO: option for editor type
|
if [[ "$_type" == "manual" ]]; then
|
||||||
[[ "$_type" == "manual" ]] && $EDITOR "$_path"
|
$EDITOR "$_path" || lib_utils::die_fatal
|
||||||
|
fi
|
||||||
;;
|
;;
|
||||||
meta)
|
meta)
|
||||||
[ -z "$global_conf_meta" ] && lib_utils::die_fatal
|
[ -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
|
# - If saved to original, opening with `--skip` will clobber the
|
||||||
# original file's comments.
|
# original file's comments.
|
||||||
local -r _skip="$(grep -E "^//!" $_path | wc -l)"
|
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...
|
# TODO: HACK: visidata saves w/ DOS-style carriage...
|
||||||
# ...but there seems to be no option out of this.
|
# ...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)
|
preprocess | rules)
|
||||||
# Run all paths through one editor instance
|
# Run all paths through one editor instance
|
||||||
|
|||||||
Reference in New Issue
Block a user