From 8d8ef812a2082ff26777d061f6c0fe9c43037d6a Mon Sep 17 00:00:00 2001 From: Ingo Karkat Date: Thu, 30 Aug 2012 12:38:54 +0200 Subject: [PATCH] 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. --- tests/t2120-shorthelp.sh | 28 ++++++++++++++++++++++++++++ todo.sh | 1 + 2 files changed, 29 insertions(+) diff --git a/tests/t2120-shorthelp.sh b/tests/t2120-shorthelp.sh index 8a08de0..58ce429 100755 --- a/tests/t2120-shorthelp.sh +++ b/tests/t2120-shorthelp.sh @@ -36,4 +36,32 @@ test_todo_session 'shorthelp output with custom action' <> custom.cfg + +test_todo_session '-h fatal error without config' <>> todo.sh -h +Fatal Error: Cannot read configuration file $HOME/.todo/config +=== 1 +EOF +test_todo_session '-h fatal error with trailing custom config' <>> 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' <>> 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 diff --git a/todo.sh b/todo.sh index a6c6c54..ea56449 100755 --- a/todo.sh +++ b/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