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:
17
todo.sh
17
todo.sh
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user