@@ -3,24 +3,26 @@ set -o errexit
3
3
set -o nounset
4
4
set -o noglob
5
5
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
20
10
}
21
11
usage () {
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
24
26
}
25
27
26
28
node_version_jq () {
@@ -45,17 +47,17 @@ node_version() {
45
47
46
48
CURRENT_DIR=$( pwd)
47
49
CONTAINER_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
49
51
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} " ;;
50
56
E)
51
57
ENV_REGEX=" $OPTARG " ;;
52
- e)
53
- EXTRA_OPTS=" ${EXTRA_OPTS:- } -e $OPTARG " ;;
54
- h)
55
- usage_noexit && exit ;;
56
58
I)
57
59
IMAGE=" $OPTARG " ;;
58
- k )
60
+ K )
59
61
RM_OPT=" " ;;
60
62
N)
61
63
IMAGE=" node:$( node_version) "
@@ -71,18 +73,19 @@ while getopts ':e:E:hI:kNM:APv:xD' OPT; do
71
73
EXTRA_OPTS=" ${EXTRA_OPTS:- } -v $CONTAINER_HOME /.npm/_git-remotes"
72
74
EXTRA_OPTS=" ${EXTRA_OPTS:- } -v $HOME /.npm:$CONTAINER_HOME /.npm"
73
75
;;
74
- v)
75
- EXTRA_OPTS=" ${EXTRA_OPTS:- } -v $OPTARG " ;;
76
76
x)
77
77
XTRACE=" y" ;;
78
78
D)
79
79
MOUNTDOCKERSOCK=" n" ;;
80
80
\? )
81
+ if [ " $OPTARG " = ' ?' ]; then
82
+ usage
83
+ fi
81
84
echo >&2 " Unknown option -$OPTARG "
82
- usage ;;
85
+ short_usage ;;
83
86
:)
84
87
echo >&2 " Missing argument for option -$OPTARG "
85
- usage ;;
88
+ short_usage ;;
86
89
esac
87
90
done
88
91
shift $(( OPTIND- 1 ))
0 commit comments