Allow multiple priorities on single run (#346)
Uses current priority logic and option tests just running multiple times until item and priority pairs are exhausted or stops on first error. Tests for multiple priorities, multiple re-prioritization and a couple of errors.
This commit is contained in:
@@ -6,7 +6,7 @@ test_description='basic priority functionality
|
|||||||
|
|
||||||
test_todo_session 'priority usage' <<EOF
|
test_todo_session 'priority usage' <<EOF
|
||||||
>>> todo.sh pri B B
|
>>> todo.sh pri B B
|
||||||
usage: todo.sh pri ITEM# PRIORITY
|
usage: todo.sh pri ITEM# PRIORITY[, ITEM# PRIORITY, ...]
|
||||||
note: PRIORITY must be anywhere from A to Z.
|
note: PRIORITY must be anywhere from A to Z.
|
||||||
=== 1
|
=== 1
|
||||||
EOF
|
EOF
|
||||||
@@ -100,4 +100,39 @@ TODO: 2 already prioritized (A).
|
|||||||
--
|
--
|
||||||
TODO: 3 of 3 tasks shown
|
TODO: 3 of 3 tasks shown
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
cat > todo.txt <<EOF
|
||||||
|
smell the uppercase Roses +flowers @outside
|
||||||
|
notice the sunflowers
|
||||||
|
stop
|
||||||
|
EOF
|
||||||
|
test_todo_session 'multiple priority' <<EOF
|
||||||
|
>>> todo.sh pri 1 A 2 B
|
||||||
|
1 (A) smell the uppercase Roses +flowers @outside
|
||||||
|
TODO: 1 prioritized (A).
|
||||||
|
2 (B) notice the sunflowers
|
||||||
|
TODO: 2 prioritized (B).
|
||||||
|
EOF
|
||||||
|
|
||||||
|
test_todo_session 'multiple reprioritize' <<EOF
|
||||||
|
>>> todo.sh pri 1 Z 2 X
|
||||||
|
1 (Z) smell the uppercase Roses +flowers @outside
|
||||||
|
TODO: 1 re-prioritized from (A) to (Z).
|
||||||
|
2 (X) notice the sunflowers
|
||||||
|
TODO: 2 re-prioritized from (B) to (X).
|
||||||
|
EOF
|
||||||
|
|
||||||
|
test_todo_session 'multiple prioritize error' <<EOF
|
||||||
|
>>> todo.sh pri 1 B 4 B
|
||||||
|
=== 1
|
||||||
|
1 (B) smell the uppercase Roses +flowers @outside
|
||||||
|
TODO: 1 re-prioritized from (Z) to (B).
|
||||||
|
TODO: No task 4.
|
||||||
|
|
||||||
|
>>> todo.sh pri 1 C 4 B 3 A
|
||||||
|
=== 1
|
||||||
|
1 (C) smell the uppercase Roses +flowers @outside
|
||||||
|
TODO: 1 re-prioritized from (B) to (C).
|
||||||
|
TODO: No task 4.
|
||||||
|
EOF
|
||||||
test_done
|
test_done
|
||||||
|
|||||||
54
todo.sh
54
todo.sh
@@ -62,7 +62,7 @@ shorthelp()
|
|||||||
listproj|lsprj [TERM...]
|
listproj|lsprj [TERM...]
|
||||||
move|mv ITEM# DEST [SRC]
|
move|mv ITEM# DEST [SRC]
|
||||||
prepend|prep ITEM# "TEXT TO PREPEND"
|
prepend|prep ITEM# "TEXT TO PREPEND"
|
||||||
pri|p ITEM# PRIORITY
|
pri|p ITEM# PRIORITY[, ITEM# PRIORITY, ...]
|
||||||
replace ITEM# "UPDATED TODO"
|
replace ITEM# "UPDATED TODO"
|
||||||
report
|
report
|
||||||
shorthelp
|
shorthelp
|
||||||
@@ -1405,38 +1405,42 @@ case $action in
|
|||||||
;;
|
;;
|
||||||
|
|
||||||
"pri" | "p" )
|
"pri" | "p" )
|
||||||
item=$2
|
shift
|
||||||
newpri=$( printf "%s\n" "$3" | tr '[:lower:]' '[:upper:]' )
|
while [ "$#" -gt 0 ] ; do
|
||||||
|
item=$1
|
||||||
|
newpri=$( printf "%s\n" "$2" | tr '[:lower:]' '[:upper:]' )
|
||||||
|
|
||||||
errmsg="usage: $TODO_SH pri ITEM# PRIORITY
|
errmsg="usage: $TODO_SH pri ITEM# PRIORITY[, ITEM# PRIORITY, ...]
|
||||||
note: PRIORITY must be anywhere from A to Z."
|
note: PRIORITY must be anywhere from A to Z."
|
||||||
|
|
||||||
[ "$#" -ne 3 ] && die "$errmsg"
|
[ "$#" -lt 2 ] && die "$errmsg"
|
||||||
[[ "$newpri" = @([A-Z]) ]] || die "$errmsg"
|
[[ "$newpri" = @([A-Z]) ]] || die "$errmsg"
|
||||||
getTodo "$item"
|
getTodo "$item"
|
||||||
|
|
||||||
oldpri=
|
oldpri=
|
||||||
if [[ "$todo" = \(?\)\ * ]]; then
|
if [[ "$todo" = \(?\)\ * ]]; then
|
||||||
oldpri=${todo:1:1}
|
oldpri=${todo:1:1}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$oldpri" != "$newpri" ]; then
|
|
||||||
sed -i.bak -e "${item}s/^(.) //" -e "${item}s/^/($newpri) /" "$TODO_FILE"
|
|
||||||
fi
|
|
||||||
if [ "$TODOTXT_VERBOSE" -gt 0 ]; then
|
|
||||||
getNewtodo "$item"
|
|
||||||
echo "$item $newtodo"
|
|
||||||
if [ "$oldpri" != "$newpri" ]; then
|
if [ "$oldpri" != "$newpri" ]; then
|
||||||
if [ "$oldpri" ]; then
|
sed -i.bak -e "${item}s/^(.) //" -e "${item}s/^/($newpri) /" "$TODO_FILE"
|
||||||
echo "TODO: $item re-prioritized from ($oldpri) to ($newpri)."
|
fi
|
||||||
else
|
if [ "$TODOTXT_VERBOSE" -gt 0 ]; then
|
||||||
echo "TODO: $item prioritized ($newpri)."
|
getNewtodo "$item"
|
||||||
|
echo "$item $newtodo"
|
||||||
|
if [ "$oldpri" != "$newpri" ]; then
|
||||||
|
if [ "$oldpri" ]; then
|
||||||
|
echo "TODO: $item re-prioritized from ($oldpri) to ($newpri)."
|
||||||
|
else
|
||||||
|
echo "TODO: $item prioritized ($newpri)."
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
if [ "$oldpri" = "$newpri" ]; then
|
||||||
if [ "$oldpri" = "$newpri" ]; then
|
echo "TODO: $item already prioritized ($newpri)."
|
||||||
echo "TODO: $item already prioritized ($newpri)."
|
fi
|
||||||
fi
|
shift; shift
|
||||||
|
done
|
||||||
;;
|
;;
|
||||||
|
|
||||||
"replace" )
|
"replace" )
|
||||||
|
|||||||
Reference in New Issue
Block a user