ENH: Print usage help for all passed actions.
Extend the support for specific usage help to built-in actions.
This commit is contained in:
66
tests/t2110-help-action.sh
Executable file
66
tests/t2110-help-action.sh
Executable file
@@ -0,0 +1,66 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
test_description='built-in actions help functionality
|
||||||
|
|
||||||
|
This test checks listing the usage help of a built-in action.
|
||||||
|
'
|
||||||
|
. ./test-lib.sh
|
||||||
|
|
||||||
|
test_todo_session 'nonexisting action help' <<'EOF'
|
||||||
|
>>> todo.sh help doesnotexist
|
||||||
|
TODO: No action "doesnotexist" exists.
|
||||||
|
=== 1
|
||||||
|
|
||||||
|
>>> todo.sh help hel
|
||||||
|
TODO: No action "hel" exists.
|
||||||
|
=== 1
|
||||||
|
|
||||||
|
>>> todo.sh help h
|
||||||
|
TODO: No action "h" exists.
|
||||||
|
=== 1
|
||||||
|
EOF
|
||||||
|
|
||||||
|
test_todo_session 'single action help' <<'EOF'
|
||||||
|
>>> todo.sh help shorthelp
|
||||||
|
shorthelp
|
||||||
|
List the one-line usage of all built-in and add-on actions.
|
||||||
|
\
|
||||||
|
EOF
|
||||||
|
|
||||||
|
test_todo_session 'multiple actions help' <<'EOF'
|
||||||
|
>>> todo.sh help shorthelp append
|
||||||
|
shorthelp
|
||||||
|
List the one-line usage of all built-in and add-on actions.
|
||||||
|
\
|
||||||
|
append ITEM# "TEXT TO APPEND"
|
||||||
|
app ITEM# "TEXT TO APPEND"
|
||||||
|
Adds TEXT TO APPEND to the end of the task on line ITEM#.
|
||||||
|
Quotes optional.
|
||||||
|
\
|
||||||
|
EOF
|
||||||
|
|
||||||
|
test_todo_session 'short and long form of action help' <<'EOF'
|
||||||
|
>>> todo.sh help append
|
||||||
|
append ITEM# "TEXT TO APPEND"
|
||||||
|
app ITEM# "TEXT TO APPEND"
|
||||||
|
Adds TEXT TO APPEND to the end of the task on line ITEM#.
|
||||||
|
Quotes optional.
|
||||||
|
\
|
||||||
|
|
||||||
|
>>> todo.sh help app
|
||||||
|
app ITEM# "TEXT TO APPEND"
|
||||||
|
Adds TEXT TO APPEND to the end of the task on line ITEM#.
|
||||||
|
Quotes optional.
|
||||||
|
\
|
||||||
|
EOF
|
||||||
|
|
||||||
|
test_todo_session 'mixed existing and nonexisting action help' <<'EOF'
|
||||||
|
>>> todo.sh help shorthelp doesnotexist list
|
||||||
|
shorthelp
|
||||||
|
List the one-line usage of all built-in and add-on actions.
|
||||||
|
\
|
||||||
|
TODO: No action "doesnotexist" exists.
|
||||||
|
=== 1
|
||||||
|
EOF
|
||||||
|
|
||||||
|
test_done
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
test_description='actions help functionality
|
test_description='custom actions help functionality
|
||||||
|
|
||||||
This test checks listing the usage help of a custom action.
|
This test checks listing the usage help of a custom action.
|
||||||
'
|
'
|
||||||
@@ -9,12 +9,13 @@ This test checks listing the usage help of a custom action.
|
|||||||
|
|
||||||
test_todo_session 'custom action help with no custom action directory' <<'EOF'
|
test_todo_session 'custom action help with no custom action directory' <<'EOF'
|
||||||
>>> todo.sh help foo
|
>>> todo.sh help foo
|
||||||
TODO: No actions directory exists.
|
TODO: No action "foo" exists.
|
||||||
=== 1
|
=== 1
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
make_action "foo"
|
make_action "foo"
|
||||||
make_action "bar"
|
make_action "bar"
|
||||||
|
make_action "ls"
|
||||||
make_action "quux"
|
make_action "quux"
|
||||||
|
|
||||||
test_todo_session 'custom action help' <<'EOF'
|
test_todo_session 'custom action help' <<'EOF'
|
||||||
@@ -41,15 +42,35 @@ EOF
|
|||||||
|
|
||||||
test_todo_session 'nonexisting action help' <<'EOF'
|
test_todo_session 'nonexisting action help' <<'EOF'
|
||||||
>>> todo.sh help doesnotexist
|
>>> todo.sh help doesnotexist
|
||||||
TODO: No add-on action "doesnotexist" exists.
|
TODO: No action "doesnotexist" exists.
|
||||||
=== 1
|
=== 1
|
||||||
|
|
||||||
>>> todo.sh help foo doesnotexist bar
|
>>> todo.sh help foo doesnotexist bar
|
||||||
foo ITEM#[, ITEM#, ...] [TERM...]
|
foo ITEM#[, ITEM#, ...] [TERM...]
|
||||||
This custom action does foo.
|
This custom action does foo.
|
||||||
\
|
\
|
||||||
TODO: No add-on action "doesnotexist" exists.
|
TODO: No action "doesnotexist" exists.
|
||||||
=== 1
|
=== 1
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
test_todo_session 'mixed built-in and custom actions help' <<'EOF'
|
||||||
|
>>> todo.sh help foo shorthelp bar
|
||||||
|
foo ITEM#[, ITEM#, ...] [TERM...]
|
||||||
|
This custom action does foo.
|
||||||
|
\
|
||||||
|
shorthelp
|
||||||
|
List the one-line usage of all built-in and add-on actions.
|
||||||
|
\
|
||||||
|
bar ITEM#[, ITEM#, ...] [TERM...]
|
||||||
|
This custom action does bar.
|
||||||
|
\
|
||||||
|
EOF
|
||||||
|
|
||||||
|
test_todo_session 'custom override of built-in action help' <<'EOF'
|
||||||
|
>>> todo.sh help ls
|
||||||
|
ls ITEM#[, ITEM#, ...] [TERM...]
|
||||||
|
This custom action does ls.
|
||||||
|
\
|
||||||
|
EOF
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
|||||||
33
todo.sh
33
todo.sh
@@ -54,7 +54,7 @@ shorthelp()
|
|||||||
del|rm ITEM# [TERM]
|
del|rm ITEM# [TERM]
|
||||||
depri|dp ITEM#[, ITEM#, ITEM#, ...]
|
depri|dp ITEM#[, ITEM#, ITEM#, ...]
|
||||||
do ITEM#[, ITEM#, ITEM#, ...]
|
do ITEM#[, ITEM#, ITEM#, ...]
|
||||||
help
|
help [ACTION...]
|
||||||
list|ls [TERM...]
|
list|ls [TERM...]
|
||||||
listall|lsa [TERM...]
|
listall|lsa [TERM...]
|
||||||
listaddons
|
listaddons
|
||||||
@@ -154,6 +154,13 @@ help()
|
|||||||
|
|
||||||
|
|
||||||
EndVerboseHelp
|
EndVerboseHelp
|
||||||
|
actionsHelp
|
||||||
|
addonHelp
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
actionsHelp()
|
||||||
|
{
|
||||||
cat <<-EndActionsHelp
|
cat <<-EndActionsHelp
|
||||||
Built-in Actions:
|
Built-in Actions:
|
||||||
add "THING I NEED TO DO +project @context"
|
add "THING I NEED TO DO +project @context"
|
||||||
@@ -200,8 +207,9 @@ help()
|
|||||||
do ITEM#[, ITEM#, ITEM#, ...]
|
do ITEM#[, ITEM#, ITEM#, ...]
|
||||||
Marks task(s) on line ITEM# as done in todo.txt.
|
Marks task(s) on line ITEM# as done in todo.txt.
|
||||||
|
|
||||||
help
|
help [ACTION...]
|
||||||
Display this help message.
|
Display help about usage, options, built-in and add-on actions,
|
||||||
|
or just the usage help for the passed ACTION(s).
|
||||||
|
|
||||||
list [TERM...]
|
list [TERM...]
|
||||||
ls [TERM...]
|
ls [TERM...]
|
||||||
@@ -278,9 +286,6 @@ help()
|
|||||||
List the one-line usage of all built-in and add-on actions.
|
List the one-line usage of all built-in and add-on actions.
|
||||||
|
|
||||||
EndActionsHelp
|
EndActionsHelp
|
||||||
|
|
||||||
addonHelp
|
|
||||||
exit 1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
addonHelp()
|
addonHelp()
|
||||||
@@ -302,21 +307,23 @@ addonHelp()
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
addonUsage()
|
actionUsage()
|
||||||
{
|
{
|
||||||
if [ -d "$TODO_ACTIONS_DIR" ]; then
|
|
||||||
for actionName
|
for actionName
|
||||||
do
|
do
|
||||||
action="${TODO_ACTIONS_DIR}/${actionName}"
|
action="${TODO_ACTIONS_DIR}/${actionName}"
|
||||||
if [ -f "$action" -a -x "$action" ]; then
|
if [ -f "$action" -a -x "$action" ]; then
|
||||||
"$action" usage
|
"$action" usage
|
||||||
else
|
else
|
||||||
die "TODO: No add-on action \"${actionName}\" exists."
|
builtinActionUsage=$(actionsHelp | sed -ne "/^ ${actionName//\//\\/}\\( \\|\$\\)/,/^\$/p")
|
||||||
|
if [ "$builtinActionUsage" ]; then
|
||||||
|
echo "$builtinActionUsage"
|
||||||
|
echo
|
||||||
|
else
|
||||||
|
die "TODO: No action \"${actionName}\" exists."
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
else
|
|
||||||
die "TODO: No actions directory exists."
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
die()
|
die()
|
||||||
@@ -1095,7 +1102,7 @@ case $action in
|
|||||||
shift ## Was help; new $1 is first help topic / action name
|
shift ## Was help; new $1 is first help topic / action name
|
||||||
if [ $# -gt 0 ]; then
|
if [ $# -gt 0 ]; then
|
||||||
# Don't use PAGER here; we don't expect much usage output from one / few actions.
|
# Don't use PAGER here; we don't expect much usage output from one / few actions.
|
||||||
addonUsage "$@"
|
actionUsage "$@"
|
||||||
else
|
else
|
||||||
if [ -t 1 ] ; then # STDOUT is a TTY
|
if [ -t 1 ] ; then # STDOUT is a TTY
|
||||||
if which "${PAGER:-less}" >/dev/null 2>&1; then
|
if which "${PAGER:-less}" >/dev/null 2>&1; then
|
||||||
|
|||||||
Reference in New Issue
Block a user