#!/bin/sh
# wrapper
# 
# Wrap a given command's output with a header and footer.

function usage() {
   echo "usage: wrapper [-H header-file] [-F footer-file] -- <command>" >&2;
   exit 2;
}
header="";
footer="";
while getopts hH:F: opt; do
	case $opt in
      H) header=$OPTARG;;
      F) footer=$OPTARG;;
      h) usage;;
	    *) echo "error: invalid option given." >&2; usage;;
	esac
done
shift $[ OPTIND - 1 ]

if [ ! -z "$header" ]; then
    cat "$header";
fi
"$@";
ec=$?;
if [ ! -z "$footer" ]; then
    cat "$footer";
fi
exit $ec;
