Skip to content
Browse files

FIX: Short help -h inaccessible when custom config is used.

When short-circuiting the option parsing, the OPTIND must be adapted, too, so that the getopts processing loop is quit correctly.
  • Loading branch information...
1 parent 50aea1e commit 8d8ef812a2082ff26777d061f6c0fe9c43037d6a @inkarkat inkarkat committed Aug 30, 2012
Showing with 29 additions and 0 deletions.
  1. +28 −0 tests/t2120-shorthelp.sh
  2. +1 −0 todo.sh
View
28 tests/t2120-shorthelp.sh
@@ -36,4 +36,32 @@ test_todo_session 'shorthelp output with custom action' <<EOF
See "help" for more details.
EOF
+
+# Verify that custom configuration is actually processed (when the -d option
+# precedes the -h option) by specifying a different actions directory and moving
+# our custom action there. The help output should mention the "Add-On Actions".
+mv todo.cfg custom.cfg
+mv .todo.actions.d custom.actions
+echo 'export TODO_ACTIONS_DIR=$HOME/custom.actions' >> custom.cfg
+
+test_todo_session '-h fatal error without config' <<EOF
+>>> todo.sh -h
+Fatal Error: Cannot read configuration file $HOME/.todo/config
+=== 1
+EOF
+test_todo_session '-h fatal error with trailing custom config' <<EOF
+>>> todo.sh -h -d custom.cfg
+Fatal Error: Cannot read configuration file $HOME/.todo/config
+=== 1
+EOF
+
+test_todo_session '-h output with preceding custom config' <<EOF
+>>> todo.sh -d custom.cfg -h | sed '/^ [A-Z]/!d'
+ Usage: todo.sh [-fhpantvV] [-d todo_config] action [task_number] [task_description]
+ Actions:
+ Actions can be added and overridden using scripts in the actions
+ Add-on Actions:
+ See "help" for more details.
+EOF
+
test_done
View
1 todo.sh
@@ -514,6 +514,7 @@ do
# Cannot just invoke shorthelp() because we need the configuration
# processed to locate the add-on actions directory.
set -- '-h' 'shorthelp'
+ OPTIND=2
;;
n )
OVR_TODOTXT_PRESERVE_LINE_NUMBERS=0

0 comments on commit 8d8ef81

Please sign in to comment.
Something went wrong with that request. Please try again.