forked from Cross-PLN-Technical-Working-Group/adpn-cli
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathadpn-do-plugins
executable file
·172 lines (130 loc) · 4.32 KB
/
adpn-do-plugins
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/bin/bash
#
# adpn-do-plugins: script to handle adpn plugins commands
#
# @version 2019.0716
SCRIPTPATH=$(which $0)
SCRIPTDIR=$(dirname $SCRIPTPATH)
SCRIPT=$(basename $SCRIPTPATH)
source "${SCRIPTDIR}/adpn-define-aliases"
__USAGE__="Usage: ${SCRIPT} [--version] [--help] <CMD> [<ARGS>]"
__HELP__="[${SCRIPT}] Try '${SCRIPT} help' for more information."
__DOC__="""${__USAGE__}
--version Display the version of the script
--help Display these usage notes
The most commonly used ${SCRIPT} commands are:
list List the available Publisher Plugins
details Report details on Publisher Plugin and required parameters
Exit codes:
0 = success (successful retrieval and expected result)
1-254 = error in executing command
255 = command not supported
"""
##########################################################################################
### COMMAND LINE: loop through switches ##################################################
##########################################################################################
declare -a _ARGV ; _ARGV=("$0")
declare -a _CMDLINE ; _CMDLINE=("$0")
declare -A _PARAM=()
shopt -s lastpipe
declare -a SWITCHFILES ; SWITCHFILES=()
if [[ -r "${CONFFILE}" ]] ; then
SWITCHFILES+=(${CONFFILE})
fi
CMDLINETXT=$(mktemp)
until [[ "$#" -lt 1 ]] ; do
_CMDLINE+=("$1")
printf "%s\n" "$1" >> "${CMDLINETXT}"
shift
done
SWITCHFILES+=(${CMDLINETXT})
adpn_command_line "${SWITCHFILES[@]}"
rm "${CMDLINETXT}"
##########################################################################################
### SCRIPT: DETERMINE COMMAND, THEN EXECUTE PIPELINE ####################################
##########################################################################################
EXITCODE=0
CMD="${_ARGV[1]}"
if [[ ! -z "${_PARAM[version]}" ]] ; then
VERSION=$(grep "^# @version" $0 | head --lines=1 | cut --only-delimited --fields=3- --delimiter=" ")
echo "${SCRIPT} version ${VERSION}"
CMD="version"
fi
if [[ ! -z "${_PARAM[help]}" ]] ; then
echo "${__DOC__}"
CMD="help"
fi
case "${CMD}" in
""|"list")
# @method adpn plugins list
# Display a list of the available publisher plugins.
#
# Usage: adpn plugins list [<WILDCARD>] [<OPTIONS>]...
#
# @version 2019.0716
declare -a APD_SWITCHES=()
if [[ "${#_ARGV[@]}" -gt 2 ]] ; then
if [[ "${_ARGV[2]:0:1}" == '/' ]] ; then
APD_SWITCHES+=(--plugin-regex="${_ARGV[2]:1:-1}")
elif [[ "${_ARGV[*]:2}" == "http:"* ]] ; then
APD_SWITCHES+=(--jar="${_ARGV[*]:2}")
elif [[ "${_ARGV[*]:2}" == *"."* ]] ; then
APD_SWITCHES+=(--plugin-id="${_ARGV[*]:2}")
else
APD_SWITCHES+=(--plugin-keywords="${_ARGV[*]:2}")
fi
fi
for KEY in "${!_PARAM[@]}" ; do
APD_SWITCHES+=("--${KEY}=${_PARAM[$KEY]}")
done
adpn-plugin-details.py "${APD_SWITCHES[@]}"
EXITCODE="$?"
;;
"details")
# @method adpn plugins details
# Display details of a single publisher plugin.
#
# Usage: adpn plugins details [<WILDCARD>] [<OPTIONS>]...
#
# @version 2019.0716
APD_OUTPUT=$(mktemp)
declare -a APD_SWITCHES=()
if [[ "${#_ARGV[@]}" -gt 2 ]] ; then
if [[ "${_ARGV[2]:0:1}" == '/' ]] ; then
APD_SWITCHES+=(--plugin-regex="${_ARGV[2]:1:-1}")
elif [[ "${_ARGV[*]:2}" == "http:"* ]] ; then
APD_SWITCHES+=(--jar="${_ARGV[*]:2}")
elif [[ "${_ARGV[*]:2}" == *"."* ]] ; then
APD_SWITCHES+=(--plugin-id="${_ARGV[*]:2}")
else
APD_SWITCHES+=(--plugin-keywords="${_ARGV[*]:2}")
fi
fi
for KEY in "${!_PARAM[@]}" ; do
APD_SWITCHES+=("--${KEY}=${_PARAM[$KEY]}")
done
adpn-plugin-details.py "${APD_SWITCHES[@]}" > "${APD_OUTPUT}" ; APD_ERRCODE="$?"
if [[ "${APD_ERRCODE}" -gt 0 ]] ; then
echo "[${SCRIPT}] '${_CMDLINE[*]:2}' matches multiple plugins." 1>&2
cat "${APD_OUTPUT}" 1>&2
elif [[ "${APD_ERRCODE}" -gt 0 ]] ; then
EXITCODE="${APD_ERRCODE}"
else
cat "${APD_OUTPUT}"
fi
rm "${APD_OUTPUT}"
EXITCODE="${APD_ERRCODE}"
;;
"version"|"help")
EXITCODE=0
;;
*)
echo "[${SCRIPT}] '${CMD}' command not understood." 1>&2
echo "${__HELP__}" 1>&2
EXITCODE=255
;;
esac
##########################################################################################
### CLEANUP: remove temporary output file. ###############################################
##########################################################################################
exit ${EXITCODE}