Merge pull request #89 from inkarkat/individual-help-enhancement

Individual help enhancement
This commit is contained in:
Gina Trapani
2012-05-12 09:59:44 -07:00
9 changed files with 311 additions and 22 deletions

51
todo.sh
View File

@@ -54,7 +54,7 @@ shorthelp()
del|rm ITEM# [TERM]
depri|dp ITEM#[, ITEM#, ITEM#, ...]
do ITEM#[, ITEM#, ITEM#, ...]
help
help [ACTION...]
list|ls [TERM...]
listall|lsa [TERM...]
listaddons
@@ -154,6 +154,12 @@ help()
EndVerboseHelp
actionsHelp
addonHelp
}
actionsHelp()
{
cat <<-EndActionsHelp
Built-in Actions:
add "THING I NEED TO DO +project @context"
@@ -200,8 +206,9 @@ help()
do ITEM#[, ITEM#, ITEM#, ...]
Marks task(s) on line ITEM# as done in todo.txt.
help
Display this help message.
help [ACTION...]
Display help about usage, options, built-in and add-on actions,
or just the usage help for the passed ACTION(s).
list [TERM...]
ls [TERM...]
@@ -280,9 +287,6 @@ help()
List the one-line usage of all built-in and add-on actions.
EndActionsHelp
addonHelp
exit 1
}
addonHelp()
@@ -304,6 +308,25 @@ addonHelp()
fi
}
actionUsage()
{
for actionName
do
action="${TODO_ACTIONS_DIR}/${actionName}"
if [ -f "$action" -a -x "$action" ]; then
"$action" usage
else
builtinActionUsage=$(actionsHelp | sed -n -e "/^ ${actionName//\//\\/} /,/^\$/p" -e "/^ ${actionName//\//\\/}$/,/^\$/p")
if [ "$builtinActionUsage" ]; then
echo "$builtinActionUsage"
echo
else
die "TODO: No action \"${actionName}\" exists."
fi
fi
done
}
die()
{
echo "$*"
@@ -1088,13 +1111,19 @@ case $action in
;;
"help" )
if [ -t 1 ] ; then # STDOUT is a TTY
if which "${PAGER:-less}" >/dev/null 2>&1; then
# we have a working PAGER (or less as a default)
help | "${PAGER:-less}" && exit 0
shift ## Was help; new $1 is first help topic / action name
if [ $# -gt 0 ]; then
# Don't use PAGER here; we don't expect much usage output from one / few actions.
actionUsage "$@"
else
if [ -t 1 ] ; then # STDOUT is a TTY
if which "${PAGER:-less}" >/dev/null 2>&1; then
# we have a working PAGER (or less as a default)
help | "${PAGER:-less}" && exit 0
fi
fi
help # just in case something failed above, we go ahead and just spew to STDOUT
fi
help # just in case something failed above, we go ahead and just spew to STDOUT
;;
"shorthelp" )