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:
|
||||
|
||||
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:
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user