I added: delete, edit, project. And added a "State".
authorlbatlle@npdl268.bpo.hp.com
Tue, 24 Oct 2006 14:47:00 +0200
changeset 1 62028bd0c3af
parent 0 65975c04088e
child 2 d086ec1aec5d
I added: delete, edit, project. And added a "State".
bug
--- a/bug	Tue Oct 24 14:23:16 2006 +0200
+++ b/bug	Tue Oct 24 14:47:00 2006 +0200
@@ -9,7 +9,7 @@
 
 function usage
 {
-	echo "usage: $PNAME <add | list | search | create>"
+	echo "usage: $PNAME <add | list | view | edit | delete | create | project>"
 }
 
 function create
@@ -79,8 +79,8 @@
 
 	LINES=`cat $1 | wc -l`
 
-	# Substract Id, Subject and Priority
-	TOTAIL=$(( LINES - 4 ))
+	# Substract Id, Subject, State and Priority
+	TOTAIL=$(( LINES - 5 ))
 	DESCRIPTION=`tail -n $TOTAIL $1 | text2db | trimlastdbNL`
 
 	echo "$ID	$PRIORITY	$STATE	$SUBJECT	$DESCRIPTION" >> $BUG_PROJECT
@@ -91,21 +91,14 @@
 function list
 {
 	echo "Id	Prior.	State	Subject"
-	LINES=`cat $BUG_PROJECT | wc -l`
-
-	# Substract Meta and sort by priority the output
-	TOTAIL=$(( LINES - 1 ))
-	tail -n $TOTAIL $BUG_PROJECT | cut -f 1,2,3 | sort -n -r -k 2
+	catlist | cut -f 1,2,3,4 | sort -n -r -k 2
 }
 
 function view
 {
 	ID=$1
 
-	LINES=`cat $BUG_PROJECT | wc -l`
-	# Substract Meta and sort by priority the output
-	TOTAIL=$(( LINES - 1 ))
-	LINE=`tail -n $TOTAIL $BUG_PROJECT | grep "^$ID"'\t'`
+	LINE=`catlist | grep "^$ID	"`
 
 	if [ "x$LINE" != "x" ]; then
 		PRIORITY=`echo "$LINE" | cut -f 2`
@@ -119,11 +112,82 @@
 		echo "Subject: $SUBJECT" | db2text
 		echo "-- Description below --"
 		echo "$DESCRIPTION" | db2text
+		return 0
+	else
+		echo "Id not found." 2>&1
+		return 1
+	fi
+}
+
+function catlist
+{
+	LINES=`cat $BUG_PROJECT | wc -l`
+	TOTAIL=$(( LINES - 1 ))
+	tail -n $TOTAIL $BUG_PROJECT | grep -v "^#"
+}
+
+function searchline
+{	
+	ID=$1
+
+	LINE=`cat $BUG_PROJECT | grep -n "^$ID	" | cut -d : -f 1`
+	if [ "x$LINE" != "x" ]; then
+		echo $LINE
+		return 0
+	else
+		return 1
+	fi
+}
+
+function delete
+{
+	ID=$1
+	LINE=`searchline $ID`
+	if [ $? -eq 0 ]; then
+		ed $BUG_PROJECT >&/dev/null << END
+$LINE
+d
+w
+q
+END
 	else
 		echo "Id not found." 2>&1
 	fi
 }
 
+function edit
+{
+	ID=$1
+
+	# Get a random file
+	FILE="/tmp/$RANDOM.txt"
+	while [ -f "$FILE" ]; do
+		FILE="/tmp/$RANDOM.txt"
+	done
+
+	view $ID > $FILE
+
+	if [ $? -eq 0 ]; then
+		MD5=`md5sum "$FILE"`
+
+		"$EDITOR" "$FILE"
+
+		MD5_bis=`md5sum "$FILE"`
+
+		if [ "$MD5" != "$MD5_bis" ]; then
+			delete $id
+			addfile "$FILE" && rm "$FILE"
+		else
+			echo "File not changed. Not changing the ticket."
+			rm "$FILE"
+		fi
+	else
+		echo "Id not found."
+		rm "$FILE"
+	fi
+
+}
+
 function add
 {	
 	# Get a random file
@@ -176,16 +240,23 @@
 	view)
 		view $2
 		;;
-	edit)
-		edit $2
+	project)
+		echo Project: $BUG_PROJECT
+		;;
+	delete)
+		delete $2
 		;;
 	create)
 		create
 		;;
+	edit)
+		edit $2
+		;;
 	*)
 		usage
 		exit 1
 		;;
 esac
+exit 0
 
 # vim:ts=8:sw=8:noet