Author: jamessan
Date: 2009-12-31 20:25:34 +0000 (Thu, 31 Dec 2009)
New Revision: 2058

Modified:
   trunk/debian/changelog
   trunk/scripts/annotate-output.1
   trunk/scripts/annotate-output.sh
Log:
annotate-output: Allow specifying a timestamp format.  (Closes: #539720)

Modified: trunk/debian/changelog
===================================================================
--- trunk/debian/changelog      2009-12-30 18:11:29 UTC (rev 2057)
+++ trunk/debian/changelog      2009-12-31 20:25:34 UTC (rev 2058)
@@ -10,6 +10,7 @@
       for the patch.  (Closes: #562857)
     + Add missing verb in description of FTP syntax.  Thanks to Marco TĂșlio
       Gontijo for the patch.  (Closes: #562586)
+  * annotate-output: Allow specifying a timestamp format.  (Closes: #539720)
 
   [ Patrick Schoenfeld ]
   * licensecheck: Add support for some common variants of the WTFPL

Modified: trunk/scripts/annotate-output.1
===================================================================
--- trunk/scripts/annotate-output.1     2009-12-30 18:11:29 UTC (rev 2057)
+++ trunk/scripts/annotate-output.1     2009-12-31 20:25:34 UTC (rev 2058)
@@ -2,12 +2,21 @@
 .SH NAME
 annotate-output \- annotate program output with time and stream
 .SH SYNOPSIS
-\fBannotate\-output\fR \fIprogram\fR [\fIargs\fR ...]
+\fBannotate\-output\fR [\fIoptions\fR] \fIprogram\fR [\fIargs\fR ...]
 .SH DESCRIPTION
 \fBannotate\-output\fR will execute the specified program, while
 prepending every line with the current time and O for stdout and E for
 stderr.
 
+.SH OPTIONS
+.TP
+\fB+FORMAT\fR
+Controls the timestamp format, as per \fBdate\fR(1).  Defaults to
+"%H:%M:%S".
+.TP
+\fB\-h\fR, \fB\-\-help\fR
+Display a help message and exit successfully.
+
 .SH EXAMPLE
 
 .nf
@@ -35,19 +44,10 @@
 might not be shown until after you have answered it.  This will give
 the impression that the annotated program has hung, while it has not.
 
-\fBannotate-output\fR does not currently accept any command-line
-options, so \-\-help, \-\-version, and that kind of stuff do not
-currently work (unless you install /usr/bin/\-\-help ;) ).
+.SH "SEE ALSO"
+\fBdate\fR(1)
 
-.SH TODO
-Accept \-\-help, \-\-version command-line options.
-
-Get rich with this very sophisticated piece of bash.
-
-.SH WEBSITE/SUPPORT
-The most recent version of this utility is on
-http://jeroen.A-Eskwadraat.nl/sw/annotate
-
+.SH SUPPORT
 This program is community-supported (meaning: you'll need to fix it
 yourself).  Patches are however appreciated, as is any feedback
 (positive or negative).

Modified: trunk/scripts/annotate-output.sh
===================================================================
--- trunk/scripts/annotate-output.sh    2009-12-30 18:11:29 UTC (rev 2057)
+++ trunk/scripts/annotate-output.sh    2009-12-31 20:25:34 UTC (rev 2058)
@@ -21,13 +21,48 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 
+progname=$(basename $0)
+
 addtime ()
 {
        while read line; do
-               echo "`date +%H:%M:%S` $1: $line"
+               echo "`date ${FMT}` $1: $line"
        done
 }
 
+usage ()
+{
+       echo \
+"Usage: $progname [options] program [args ...]
+  Run program and annotate STDOUT/STDERR with a timestamp.
+
+  Options:
+   +FORMAT    - Controls the timestamp format as per date(1)
+   -h, --help - Show this message"
+}
+
+FMT="+%H:%M:%S"
+while [ "$1" ]; do
+       case "$1" in
+       +*)
+               FMT="$1"
+               shift
+               ;;
+       -h|-help|--help)
+               usage
+               exit 0
+               ;;
+       *)
+               break
+               ;;
+       esac
+done
+
+if [ $# -lt 1 ]; then
+       usage
+       exit 1
+fi
+
 OUT=`mktemp /tmp/annotate.XXXXXX` || exit 1
 ERR=`mktemp /tmp/annotate.XXXXXX` || exit 1
 
@@ -37,11 +72,11 @@
 addtime O < $OUT &
 addtime E < $ERR &
 
-echo "`date +%H:%M:%S` I: Started $@"
+echo "`date ${FMT}` I: Started $@"
 "$@" > $OUT 2> $ERR ; EXIT=$?
 rm -f $OUT $ERR
 wait
 
-echo "`date +%H:%M:%S` I: Finished with exitcode $EXIT"
+echo "`date ${FMT}` I: Finished with exitcode $EXIT"
 
 exit $EXIT



-- 
To unsubscribe, send mail to [email protected].

Reply via email to