-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdev
executable file
·65 lines (57 loc) · 1.23 KB
/
dev
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env bash
SCRIPT_NAME=$(basename $0)
DEV_SUBCOMMANDS=(
'up'
'shell'
'test'
'package'
'upload'
)
log() {
echo "$SCRIPT_NAME: $(date): INFO: $*" 1>&2
}
error() {
echo "$SCRIPT_NAME: $(date): ERROR: $*" 1>&2
}
die() {
error "$*"
exit 1
}
check_requires() {
log "Running $SCRIPT_NAME with env:"
for r in $@; do
if ! printenv "$r" > /dev/null; then
die "Could not find required env var: '$r'"
fi
echo " $r=$(printenv $r)" 1>&2
done
}
export_env() {
git_branch="$(git branch --show)"
if [ -z "$git_branch" ]; then
error "HEAD is not attached; no git_branch is available."
fi
export ROOT_DIR=$(dirname $SCRIPT_NAME)
export TARGET_ENV="$git_branch"
}
run() {
if [ -z "$1" ] || [[ "$1" == 'help' ]]; then
echo "Usage: $SCRIPT_NAME [${DEV_SUBCOMMANDS[@]}]"
else
export_env
script="$ROOT_DIR/bin/dev-$1"
if [ -x "$script" ]; then
shift
"$script" $*
else
die "Provided subcommand: '$1' is not valid; no executable script $script"
fi
fi
return $?
}
# Only run & exit if this script is called directly; run & exit will
# not be called if dev is being sourced with '.' or 'source'
if [ "${BASH_SOURCE[0]}" -ef "$0" ]; then
run $*
exit $?
fi