ENH: Handle -h, shorthelp and help when a Fatal Error happens.

The user may need the help to solve any fatal error that appears while todo.sh isn't properly set up. As the help actions do not depend on any setting that the fatal errors check, we can still invoke them.

Factor out dieWithHelp() and use that for printing the fatal errors.
This commit is contained in:
Ingo Karkat
2012-08-30 13:16:02 +02:00
parent 8d8ef812a2
commit 8ff79102a5
2 changed files with 33 additions and 12 deletions

17
todo.sh
View File

@@ -81,7 +81,6 @@ shorthelp()
See "help" for more details.
EndHelpFooter
exit 0
}
help()
@@ -327,6 +326,16 @@ actionUsage()
done
}
dieWithHelp()
{
case "$1" in
help) help;;
shorthelp) shorthelp;;
esac
shift
die "$@"
}
die()
{
echo "$*"
@@ -655,7 +664,7 @@ fi
}
# === SANITY CHECKS (thanks Karl!) ===
[ -r "$TODOTXT_CFG_FILE" ] || die "Fatal Error: Cannot read configuration file $TODOTXT_CFG_FILE"
[ -r "$TODOTXT_CFG_FILE" ] || dieWithHelp "$1" "Fatal Error: Cannot read configuration file $TODOTXT_CFG_FILE"
. "$TODOTXT_CFG_FILE"
@@ -694,8 +703,8 @@ fi
ACTION=${1:-$TODOTXT_DEFAULT_ACTION}
[ -z "$ACTION" ] && usage
[ -d "$TODO_DIR" ] || die "Fatal Error: $TODO_DIR is not a directory"
( cd "$TODO_DIR" ) || die "Fatal Error: Unable to cd to $TODO_DIR"
[ -d "$TODO_DIR" ] || dieWithHelp "$1" "Fatal Error: $TODO_DIR is not a directory"
( cd "$TODO_DIR" ) || dieWithHelp "$1" "Fatal Error: Unable to cd to $TODO_DIR"
[ -f "$TODO_FILE" ] || cp /dev/null "$TODO_FILE"
[ -f "$DONE_FILE" ] || cp /dev/null "$DONE_FILE"