#!/bin/bash
#########################################################
# 							#
# This is BashStyle-NG  				#
#							#
# Licensed under GNU GENERAL PUBLIC LICENSE v3    	#
#							#
# Copyright 2007 - 2017 Christopher Bratusek		#
#							#
#########################################################

case ${1} in

	-h | --help | "")
		bashstyle-help -a "Christopher Roy Bratusek" -e "nano@jpberlin.de" -h "http://www.nanolx.org"\
			-l "GNU GPL v3" -n "xmltagdelete" -s "delete tag from xml files"\
			-v "${BSNG_VERSION}" -y "${BSNG_YEAR}"\
			-o "infile:|xml file to alter"\
			-o "starttag:<property name=something>|start tag to look for"\
			-o "endtag:</property>|end tag to look for"\
			-o "outfile:|output xml file (optional, infile.new if unset)"
	;;

	*)
		if [[ $# -lt 3 ]]; then
			echo "Not enough arguments"
			exit 1
		fi

		infile="${1}"

		starttag=${2/\//\\/}
		endtag=${3/\//\\/}

		if [[ ${4} ]]; then
			outfile="${4}"
		else	outfile=$(basename "${infile}").new
		fi

		sed "/${starttag}/,/${endtag}/d" "${infile}" > "${outfile}"
		;;

esac
