From f604e0b771241f49b5493c38915832dd73a0fff6 Mon Sep 17 00:00:00 2001 From: Ambrose Chua Date: Sun, 1 Apr 2018 22:55:11 +0800 Subject: [PATCH] Add help message --- .runenv | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/.runenv b/.runenv index 747ad44..c19fec7 100644 --- a/.runenv +++ b/.runenv @@ -2,13 +2,26 @@ OPTIND=1 -# Options delete="" name="" ports="" volumes="" -while getopts "xn:p:v:" opt; do +show_help() { +cat << EOF +Usage: ${0##*/} [-hx] [-n NAME] [-p PORT]... [-v LIST]... [CMD]... +Starts an env Docker container. If CMD is specified, starts CMD +instead of a shell. + + -h display this help and exit + -x delete Docker container after exit. will loose data + -p PORT forward host PORT to container PORT + -v LIST mount volume LIST. specify as LOCAL:MOUNT + +EOF +} + +while getopts "hxn:p:v:" opt; do case "$opt" in x) delete="--rm " @@ -22,12 +35,18 @@ while getopts "xn:p:v:" opt; do v) volumes="$volumes\n\t-v $OPTARG " ;; + h) + show_help + exit 0 + ;; :) echo "Option -$OPTARG requires an argument." >&2 + show_help exit 1 ;; \?) echo "Invalid option: -$OPTARG" >&2 + show_help exit 1 ;; esac