-
Notifications
You must be signed in to change notification settings - Fork 1
/
p-java.sh
executable file
·112 lines (89 loc) · 2.37 KB
/
p-java.sh
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
#!/bin/bash
set -xeuo pipefail
SCRIPTNAME=${0##*/}
__DOC__="
================================================================================
$SCRIPTNAME MANUAL
================================================================================
This script helps to get java related programming tasks done fast.
"
# All output should be in English
export LC_ALL=C
function showHelp {
echo "
USAGE:
$SCRIPTNAME [OPTIONS]
This is a script that helps to get java related programming tasks done fast.
OPTIONS:
-h, --help Show this help message
--manual Show the manual of this command
-m, --mvngenerate Generate a new maven project
"
exit 0
}
function showError {
echo "$SCRIPTNAME $1" >&2
exit 1
}
function checkArguments {
if test $1 -lt $2; then
showError "$3"
fi
}
# callPgCtl
# Call the PostgreSQL control program pg_ctl, either with or without log file
# output.
#
# $1 - pg_ctl command (ex., status, start, stop)
# $2 - data dir of the PostgreSQL cluster
# $3 - server port
# $4 - log file
function mvnGenerate {
mvn -B archetype:generate \
-DarchetypeGroupId=org.apache.maven.archetypes \
-DgroupId="$1" \
-DartifactId="$2"
return $?
}
################################################################################
## MAIN
################################################################################
# Handling of script arguments...
# Each short option character in shortopts may be followed by one colon to
# indicate it has a required argument, and by two colons to indicate it has
# an optional argument.
ARGS=$(
getopt -o "hm" \
-l "help,manual,mvngenerate" \
-n $SCRIPTNAME -- "$@"
)
if [ $? != 0 ] ; then
showError "Wrong argument given: $@"
fi
eval set -- "$ARGS"
test $# == 1 || test "$1" == "-h" || test "$1" == "--help" && {
showHelp
exit 0
}
test "$1" == "--manual" && {
echo "$__DOC__"
echo
showHelp
exit 0
}
CMD=
while true; do
case "$1" in
-m | --mvngenerate)
checkArguments $# 3 "$1: ERROR: Specify a groupId and an artifactId. Ex.: com.example.mylibrary fancy-app"
mvnGenerate $3 $4
exit $?
;;
-- )
shift
break
;;
esac
done
# We should not reach this line!
showError "No parameter specified"