--- a/bug Wed Oct 25 19:37:54 2006 +0200
+++ b/bug Mon Jan 15 20:21:54 2007 +0100
@@ -45,17 +45,31 @@
# bug delete <ID>
# Do that whenever you will not need the issue anymore.
#
+#
+# Contributions:
+# --------------
+#
+# pancake <pancake@youterm.com>
+# - drop bashisms
+# - implement -h flag
+# - error messages to stderr
+# - more checks and help on BUG_PROJECT environ
+#
+# TODO:
+# Support for an array of bug report files ?? readonly
+# Check BUG_PROJECT file format before processing
+#
PNAME=`basename "$0"`
CMD="$1"
-if [ "x$EDITOR" == "x" ]; then
+if [ -z "$EDITOR" ]; then
EDITOR=vim
fi
function usage
{
- echo "usage: $PNAME <add | list | view | edit | delete | create | project>"
+ echo "Usage: $PNAME [ add | list | view | edit | delete | create | project ]"
}
function create
@@ -124,15 +138,21 @@
STATE=`grep "^State:" $1 | head -n 1 | cut -d : -f 2- | string2db`
PRIORITY=`grep "^Priority:" $1 | head -n 1 | cut -d : -f 2- | string2db`
- if ( [ "x$SUBJECT" == "" ] || [ "x$PRIORITY" == "" ] ); then
- echo "Error in ticket: subject or priority." 2>&1
+ if [ -z "$PRIORITY" ]; then
+ echo "Error in ticket: subject or priority." > /dev/stderr
+ return 1
+ fi
+
+ if [ -z "$SUBJECT" ]; then
+ echo "Error in ticket: subject or priority." > /dev/stderr
return 1
fi
LINES=`cat $1 | wc -l`
# Substract Id, Subject, State and Priority
- TOTAIL=$(( LINES - 5 ))
+ #TOTAIL=$(( LINES - 5 ))
+ let TOTAIL=LINES-5
DESCRIPTION=`tail -n $TOTAIL $1 | text2db | trimlastdbNL`
echo "$ID $PRIORITY $STATE $SUBJECT $DESCRIPTION" >> $BUG_PROJECT
@@ -160,7 +180,7 @@
LINE=`catlist | grep "^$ID "`
- if [ "x$LINE" != "x" ]; then
+ if [ -n "$LINE" ]; then
PRIORITY=`echo "$LINE" | cut -f 2`
STATE=`echo "$LINE" | cut -f 3`
SUBJECT=`echo "$LINE" | cut -f 4`
@@ -182,7 +202,8 @@
function catlist
{
LINES=`cat $BUG_PROJECT | wc -l`
- TOTAIL=$(( LINES - 1 ))
+ let TOTAIL=LINES-1
+ #TOTAIL=$(( LINES - 1 ))
tail -n $TOTAIL $BUG_PROJECT | grep -v "^#"
}
@@ -191,7 +212,7 @@
ID=$1
LINE=`cat $BUG_PROJECT | grep -n "^$ID " | cut -d : -f 1`
- if [ "x$LINE" != "x" ]; then
+ if [ -n "$LINE" ]; then
echo $LINE
return 0
else
@@ -245,7 +266,6 @@
echo "Id not found."
rm "$FILE"
fi
-
}
function add
@@ -260,8 +280,8 @@
cat > "$FILE" << TEMPLATE
Id: $ID
-Priority:
-State:
+Priority:
+State:
Subject:
-- Description below --
TEMPLATE
@@ -280,17 +300,33 @@
}
-if [ "x$BUG_PROJECT" == "x" ]; then
- echo "\$BUG_PROJECT is not set"
+if [ -z "$BUG_PROJECT" ]; then
+ echo "\$BUG_PROJECT is not set."
exit 1
fi
-if [ "x$CMD" == "x" ]; then
+if [ ! "`echo $BUG_PROJECT | cut -c 1`" = "/" ]; then
+ echo "Do not use relative paths in BUG_PROJECT environ."
+ exit 1
+fi
+
+if [ ! "$CMD" = "create" ]; then
+if [ ! -f "$BUG_PROJECT" ]; then
+ echo "BUG_PROJECT file does not exist. Type 'bug create'"
+ exit 0
+fi
+fi
+
+if [ -z "$CMD" ]; then
usage
exit 1
fi
case "$CMD" in
+ -h)
+ echo "Usage: bug [[alvpe] [del] [create]] [args]"
+ exit 1
+ ;;
a*)
add || exit 1
;;