#!/bin/bash usage() { echo "Usage: $0 [-h] [-m|M] [-p]" 1>&2; echo " -h: This message" 1>&2; echo " -p: Pre release" 1>&2; echo " -m: Increment minor" 1>&2; echo " -M: Increment major" 1>&2; } PRE_RELEASE=0 ALTERS=0 ALTER_NAME="release" while getopts "hpmMr" o; do case "${o}" in p) PRE_RELEASE=1 ;; r) ALTERS=$ALTERS+1 ALTER_NAME="release" ;; m) ALTERS=$ALTERS+1 ALTER_NAME="minor" ;; M) ALTERS=$ALTERS+1 ALTER_NAME="major" ;; h) usage exit 0; ;; *) printerr "Unsupported option ${o}" usage exit 1; ;; esac done if [[ $ALTERS -gt 1 ]]; then echo "You can specify exactly one option between m and M" usage exit 1; fi CURRENT_VERSION=`./latest-ver.sh` INCREMENT_NAME=$ALTER_NAME if [[ $PRE_RELEASE -gt 0 ]]; then INCREMENT_NAME="pre$INCREMENT_NAME" fi NEW_VERSION=`semver $CURRENT_VERSION --preid rc -i $INCREMENT_NAME` echo "$NEW_VERSION"