-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathsnow
196 lines (179 loc) · 5.54 KB
/
snow
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#!/bin/bash
# SNOW-RUN. Terminal interface to Service-Now.
# Copyright (C) 2019 Martin Chovanec [[email protected]]
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# ---------------
# This is the entry script for SNOW RUN
# it routes commands to actual scripts that execute them
# Get the directory in which the current script resides. It's not a bullet-proof solution, but it works under normal circumstances
my_dir=$(dirname $0)
# Function that handles what happens when the command starts with snow attachment
function handle_attachment {
command=$1
shift
case $command in
# known command
list)
exec $my_dir/../include/attachment-list.sh "$@"
;;
# nothing or unknown command
*)
# if the SNOW_AUTOCOMPLETE variable is set, we just print the options available for snow attachment
# it is assumed that SNOW_AUTOCOMPLETE is set when bash is trying to offer the user possible commands (autocompletion)
# see include/autocomplete.sh
if [[ -n $SNOW_AUTOCOMPLETE ]]
then
echo list
exit 1
fi
echo "Available options: list TABLE_NAME" >&2
exit 1
;;
esac
}
# Handle snow scriptinclude
function handle_scriptinclude {
command=$1
shift
case $command in
search)
exec $my_dir/../include/snow-scriptinclude-search.sh "$@"
;;
*)
if [[ -n $SNOW_AUTOCOMPLETE ]]
then
echo search
exit 1
fi
echo "Available options: search SCRIPT_INCLUDE_NAME" >&2
exit 1
;;
esac
}
# Handle snow table
function handle_table {
command=$1
shift
case $command in
search)
exec $my_dir/../include/snow-table-search.sh "$@"
;;
fields)
exec $my_dir/../include/snow-table-fields.sh "$@"
;;
*)
if [[ -n $SNOW_AUTOCOMPLETE ]]
then
echo "search fields"
exit 1
fi
echo "Available options: $(SNOW_AUTOCOMPLETE=1 handle_table)" >&2
exit 1
;;
esac
}
# Handle snow record or snow r
function handle_record {
command=$1
shift
case $command in
search)
exec $my_dir/../include/snow-record-search.sh "$@"
;;
delete)
exec $my_dir/../include/snow-record-delete.sh "$@"
;;
insert)
exec $my_dir/../include/snow-record-update.sh "$@"
;;
*)
if [[ -n $SNOW_AUTOCOMPLETE ]]
then
echo "search delete insert"
exit 1
fi
echo "Available options: $(SNOW_AUTOCOMPLETE=1 handle_table)" >&2
exit 1
;;
esac
}
command=$1
shift
# top-level command selection (e.g. snow run, snow login, ...)
case $command in
login)
exec $my_dir/../include/snow-login.sh
;;
info)
exec $my_dir/../include/snow-info.sh
;;
elevate)
exec $my_dir/../include/snow-elevate.sh
;;
eval)
exec $my_dir/../include/snow-eval.sh "$@"
;;
e|exec)
exec $my_dir/../include/snow-exec.sh "$@"
;;
inspect)
exec $my_dir/../include/snow-inspect.sh "$@"
;;
run)
exec $my_dir/../include/snow-run.sh "$@"
;;
scriptinclude)
handle_scriptinclude "$@"
exit $?
;;
table)
handle_table "$@"
exit $?
;;
r|record)
handle_record "$@"
exit $?
;;
attachment)
handle_attachment "$@"
exit $?
;;
--include-dir|-I)
echo $my_dir/../include
exit $?
;;
operators|op)
echo "Available operators for queries in ServiceNow:"
OFS="\t" echo "= != > < >= <= != STARTSWITH CONTAINS IN ENDSWITH 'DOES NOT CONTAIN' 'NOT IN'"
exit
;;
*)
# is the argument a script in the js directory?
if [[ -e $my_dir/../js/$command.js ]]
then
exec $0 exec "$command" "$@"
fi
if [[ -n $SNOW_AUTOCOMPLETE ]]
then
echo "--version attachment login info elevate eval exec inspect run scriptinclude table record operators $(cd $my_dir/../js; ls *.js | sed 's/\.js//g' | tr '\n' ' ')"
exit 1
fi
notice="SNOW-RUN Copyright (C) 2019 Martin Chovanec <[email protected]>
This program comes with ABSOLUTELY NO WARRANTY; for details refer to GNU GPL.
This is free software, and you are welcome to redistribute it
under certain conditions; refer to GNU GPL for details."
echo "$notice"
echo ""
echo "Available options: $(SNOW_AUTOCOMPLETE=1 $0)"
echo "Full documentation is available in the README.md file as well as on https://github.com/chovanecm/snow-run"
exit 1
esac