-
Notifications
You must be signed in to change notification settings - Fork 0
/
jz
executable file
·138 lines (111 loc) · 3.25 KB
/
jz
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/usr/bin/env bash
set -o pipefail # pipe fails with first failing command
set -o errexit # exit script on failed command
shopt -s nullglob
export JZ_ROOT=${JZ_ROOT:-"$(dirname "$(readlink -f "$0")")"}
export PLUGIN_PATH=${PLUGIN_PATH:="$JZ_ROOT/plugins"}
source "$PLUGIN_PATH/common/functions"
parse_args "$@"
[[ $JZ_TRACE ]] && set -x
# Find project-local config-file first (because base script defines variables that might be based on project-specific scripts)
path_node=$(pwd)
while true; do
if [[ $path_node == / ]]; then
# nothing found
break
elif [ -f "${path_node}/.jeeez" ]; then
# found
log_debug "Sourced specific config from $path_node/.jeeez"
source $path_node/.jeeez
export JZ_CUSTOM_RC=$path_node/.jeeez
export JZ_CUSTOM_ROOT=$path_node
break
else
# go up
path_node="$(dirname "$path_node")"
fi
done
case "$(uname -s)" in
CYGWIN*)
export JZ_DISTRO=${JZ_DISTRO:="cygwin"}
;;
*)
export JZ_DISTRO=${JZ_DISTRO:="linux"}
;;
esac
[[ -f ~/.jeeez/config ]] && source ~/.jeeez/config
[[ -d ~/.jeeez ]] && for f in ~/.jeeez/config-$JZ_DISTRO/*; do source "$f"; done
[[ -f $JZ_ROOT/jeeez.config ]] && source "$JZ_ROOT/jeeez.config"
[[ $JZ_TRACE ]] && set -x
export JZ_LOGS=~/.jeeez/logs
[[ ! -d $JZ_LOGS ]] && mkdir -p $JZ_LOGS
export JZ_CACHE=~/.jeeez/cache
[[ ! -d $JZ_LJZ_CACHEOGS ]] && mkdir -p $JZ_CACHE
export JZ_HISLOG=$JZ_LOGS/history.log
if [[ $JZ_DISTRO == "cygwin" ]]; then
export BATCH_TYPE=${BATCH_TYPE:-"cmd"}
else
export BATCH_TYPE=${BATCH_TYPE:-"sh"}
fi
args=("$@")
for arg in "$@"; do
if [[ "$arg" =~ ^--.* ]]; then
shift 1
else
break
fi
done
! has_tty && JZ_QUIET_OUTPUT=1
execute_jz_cmd() {
local PLUGIN_NAME="$1"
local PLUGIN_CMD="$2"
local implemented=0; local script
local argv=("$@")
if [[ -x $PLUGIN_PATH/$PLUGIN_NAME/subcommands/default ]]; then
"$PLUGIN_PATH/$PLUGIN_NAME/subcommands/default" "$@"
implemented=1
elif [[ -x $PLUGIN_PATH/${PLUGIN_NAME%%:*}/subcommands/${1#*:} ]]; then
shift 1
"$PLUGIN_PATH/${PLUGIN_NAME%%:*}/subcommands/${PLUGIN_NAME#*:}" "$@"
implemented=1
fi
if [[ $implemented -eq 0 ]];then
for script in $PLUGIN_PATH/*/commands; do
set +e; $script "$@" ; exit_code=$? ; set -e
if [[ "$exit_code" -eq 1 ]]; then
continue
fi
implemented=1
done
fi
if [[ "$implemented" -eq 0 ]]; then
log_warn "\`$*\` is not a valid command."
log_warn "See \`jz help\` for a list of available commands."
exit 1
fi
}
case "$1" in
help|'')
export LC_ALL=C # so sort will respect non alpha characters
ALL_PLUGIN_COMMANDS=$(find -L "$PLUGIN_PATH/" -name commands 2> /dev/null || true)
for plugin_command in $ALL_PLUGIN_COMMANDS;do
PLUGIN_COMMANDS+="$plugin_command "
done
echo "JEEEZ (short: jz) is an simple but opinionated command-line Java EE-project scaffolding tool"
echo "Usage: jz PLUGIN:COMMAND [OPTIONS]"
echo ""
echo "Commands:"
echo ""
for plugin_command in $PLUGIN_COMMANDS; do
$plugin_command help
done | sort | column -c2 -t -s';'
if [[ $JZ_DEBUG ]]; then
echo ""
echo "Debug Info:"
env | grep JZ_
fi
;;
*)
execute_jz_cmd "$@"
;;
esac