@@ -3,24 +3,26 @@ set -o errexit
33set -o nounset
44set -o noglob
55
6- usage_noexit () {
7- echo >&2 ' Usage: drun [-hkx] [-N [-A] [-P] [-M (alpine|wheezy|slim)]] [-E ENV_REGEX] [-e ENV_SPEC]* [-v VOL_SPEC]* [(-I image)|(image)] [command]'
8- echo >&2 ' -h Help'
9- echo >&2 ' -k Keep container after run (i.e. does not user docker run --rm option)'
10- echo >&2 ' -x Enables bash xtrace so that exact `docker run` command is displayed'
11- echo >&2 ' -N Uses node:AUTO image, where AUTO is detected from a local package.json if any (also mounts .npmrc, if present)'
12- echo >&2 ' -M ALT_IMAGE Prefers node ALT_IMAGE (can be either alpine, wheezy or slim) (e.g., with -NM slim, will resolve to node:AUTO-slim)'
13- echo >&2 ' -A Prefers mhart/alpine-node-auto images (e.g., with -NA, will resolve to mhart/alpine-node-auto:AUTO)'
14- echo >&2 ' -P Mounts your ~/.npm/ into the container (Only useful with node, obviously)'
15- echo >&2 ' -v VOL_SPEC Adds a --volume option to `docker run`'
16- echo >&2 ' -e ENV_SPEC Adds a --env option to `docker run`'
17- echo >&2 ' -E ENV_REGEX Forwards local env variables whose names match ENV_REGEX to container'
18- echo >&2 ' -I image Tells which docker image to use'
19- echo >&2 ' -D Do not mount /var/run/docker.sock into the container'
6+ short_usage () {
7+ echo >&2 ' Usage: drun [options] (image|-I image) [--] [command]'
8+ echo >&2 ' See `drun -?` for help.'
9+ exit 1
2010}
2111usage () {
22- usage_noexit
23- exit 1
12+ echo >&2 ' Usage: drun [options] (image|-I image) [--] [command]'
13+ echo >&2 ' -? Shows this help'
14+ echo >&2 ' -K Keep container after run (i.e. does not user docker run --rm option)'
15+ echo >&2 ' -x Enables bash xtrace so that exact `docker run` command is displayed'
16+ echo >&2 ' -N Uses node:AUTO image, where AUTO is detected from a local package.json if any (also mounts .npmrc, if present)'
17+ echo >&2 ' -M ALT_IMAGE Prefers node ALT_IMAGE (can be either alpine, wheezy or slim) (e.g., with -NM slim, will resolve to node:AUTO-slim)'
18+ echo >&2 ' -A Prefers mhart/alpine-node-auto images (e.g., with -NA, will resolve to mhart/alpine-node-auto:AUTO)'
19+ echo >&2 ' -P Mounts your ~/.npm/ into the container (Only useful with node, obviously)'
20+ echo >&2 ' -E ENV_REGEX Forwards local env variables whose names match ENV_REGEX to container'
21+ echo >&2 ' -I image Tells which docker image to use, allowing other options to set later'
22+ echo >&2 ' -D Do not mount /var/run/docker.sock into the container'
23+ echo >&2 ' -X SOME_DOCKER_OPTION Passes option directly to docker (e.g. `drun -X --dns=8.8.8.8` results in `docker run --dns=8.8.8.8 ...`)'
24+ echo >&2 ' -a|c|e|h|l|m|p|u|v|w VAL Work exactly like `docker run` options (e.g. `drun -e FOO=bar` results in `docker run -e FOO=bar ...`)'
25+ exit 0
2426}
2527
2628node_version_jq () {
@@ -45,17 +47,17 @@ node_version() {
4547
4648CURRENT_DIR=$( pwd)
4749CONTAINER_HOME=$CURRENT_DIR
48- while getopts ' :e:E:hI:kNM:APv:xD ' OPT; do
50+ while getopts ' :a:c:e:h:l:m:p:u:v:w:X:E:I:KNM:APxD ' OPT; do
4951 case $OPT in
52+ a|c|e|h|l|m|p|u|v|w)
53+ EXTRA_OPTS=" ${EXTRA_OPTS:- } -${OPT} ${OPTARG} " ;;
54+ X)
55+ EXTRA_OPTS=" ${EXTRA_OPTS:- } ${OPTARG} " ;;
5056 E)
5157 ENV_REGEX=" $OPTARG " ;;
52- e)
53- EXTRA_OPTS=" ${EXTRA_OPTS:- } -e $OPTARG " ;;
54- h)
55- usage_noexit && exit ;;
5658 I)
5759 IMAGE=" $OPTARG " ;;
58- k )
60+ K )
5961 RM_OPT=" " ;;
6062 N)
6163 IMAGE=" node:$( node_version) "
@@ -71,18 +73,19 @@ while getopts ':e:E:hI:kNM:APv:xD' OPT; do
7173 EXTRA_OPTS=" ${EXTRA_OPTS:- } -v $CONTAINER_HOME /.npm/_git-remotes"
7274 EXTRA_OPTS=" ${EXTRA_OPTS:- } -v $HOME /.npm:$CONTAINER_HOME /.npm"
7375 ;;
74- v)
75- EXTRA_OPTS=" ${EXTRA_OPTS:- } -v $OPTARG " ;;
7676 x)
7777 XTRACE=" y" ;;
7878 D)
7979 MOUNTDOCKERSOCK=" n" ;;
8080 \? )
81+ if [ " $OPTARG " = ' ?' ]; then
82+ usage
83+ fi
8184 echo >&2 " Unknown option -$OPTARG "
82- usage ;;
85+ short_usage ;;
8386 :)
8487 echo >&2 " Missing argument for option -$OPTARG "
85- usage ;;
88+ short_usage ;;
8689 esac
8790done
8891shift $(( OPTIND- 1 ))
0 commit comments