-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy path_spool
322 lines (307 loc) · 14.3 KB
/
_spool
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
#compdef spool
# -----------------------------------------------------------------------------
# The BSD-3-Clause License
#
# Copyright (c) 2020, Koichi Shiraishi
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# * Neither the name of que nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
# -----------------------------------------------------------------------------
#
# github.com/gcpug/spool
#
# -----------------------------------------------------------------------------
#
# usage: spool [<flags>] <command> [<args> ...]
#
# A CLI tool to manage Cloud Spanner databases for testing.
#
# Flags:
# --help Show context-sensitive help (also try --help-long and
# --help-man).
# -p, --project=PROJECT Set GCP project ID. (use $SPANNER_PROJECT_ID or
# $GOOGLE_CLOUD_PROJECT as default value)
# -i, --instance=INSTANCE Set Cloud Spanner instance name. (use
# $SPANNER_INSTANCE_ID as default value)
# -d, --database=DATABASE Set Cloud Spanner database name. (use
# $SPOOL_SPANNER_DATABASE_ID as default value)
# -s, --schema=SCHEMA Set schema file path.
#
# Commands:
# help [<command>...]
# Show help.
#
# setup
# Setup the database for spool metadata.
#
# create --db-name-prefix=DB-NAME-PREFIX [<flags>]
# Add new databases to the pool.
#
# get
# Get a idle database from the pool.
#
# get-or-create --db-name-prefix=DB-NAME-PREFIX
# Get or create a idle database from the pool.
#
# list [<flags>]
# Print databases.
#
# put <database>
# Return the database to the pool.
#
# clean [<flags>]
# Drop all idle databases.
#
# -----------------------------------------------------------------------------
#
# usage: spool setup
#
# Setup the database for spool metadata.
#
# Flags:
# --help Show context-sensitive help (also try --help-long and
# --help-man).
# -p, --project=PROJECT Set GCP project ID. (use $SPANNER_PROJECT_ID or
# $GOOGLE_CLOUD_PROJECT as default value)
# -i, --instance=INSTANCE Set Cloud Spanner instance name. (use
# $SPANNER_INSTANCE_ID as default value)
# -d, --database=DATABASE Set Cloud Spanner database name. (use
# $SPOOL_SPANNER_DATABASE_ID as default value)
# -s, --schema=SCHEMA Set schema file path.
#
# -----------------------------------------------------------------------------
#
# usage: spool create --db-name-prefix=DB-NAME-PREFIX [<flags>]
#
# Add new databases to the pool.
#
# Flags:
# --help Show context-sensitive help (also try --help-long and
# --help-man).
# -p, --project=PROJECT Set GCP project ID. (use $SPANNER_PROJECT_ID or
# $GOOGLE_CLOUD_PROJECT as default value)
# -i, --instance=INSTANCE Set Cloud Spanner instance name. (use
# $SPANNER_INSTANCE_ID as default value)
# -d, --database=DATABASE Set Cloud Spanner database name. (use
# $SPOOL_SPANNER_DATABASE_ID as default value)
# -s, --schema=SCHEMA Set schema file path.
# --db-name-prefix=DB-NAME-PREFIX
# Set new database name prefix.
# --num=1 Set the number of new databases.
#
# -----------------------------------------------------------------------------
#
# usage: spool get
#
# Get a idle database from the pool.
#
# Flags:
# --help Show context-sensitive help (also try --help-long and
# --help-man).
# -p, --project=PROJECT Set GCP project ID. (use $SPANNER_PROJECT_ID or
# $GOOGLE_CLOUD_PROJECT as default value)
# -i, --instance=INSTANCE Set Cloud Spanner instance name. (use
# $SPANNER_INSTANCE_ID as default value)
# -d, --database=DATABASE Set Cloud Spanner database name. (use
# $SPOOL_SPANNER_DATABASE_ID as default value)
# -s, --schema=SCHEMA Set schema file path.
#
# -----------------------------------------------------------------------------
#
# usage: spool get-or-create --db-name-prefix=DB-NAME-PREFIX
#
# Get or create a idle database from the pool.
#
# Flags:
# --help Show context-sensitive help (also try --help-long and
# --help-man).
# -p, --project=PROJECT Set GCP project ID. (use $SPANNER_PROJECT_ID or
# $GOOGLE_CLOUD_PROJECT as default value)
# -i, --instance=INSTANCE Set Cloud Spanner instance name. (use
# $SPANNER_INSTANCE_ID as default value)
# -d, --database=DATABASE Set Cloud Spanner database name. (use
# $SPOOL_SPANNER_DATABASE_ID as default value)
# -s, --schema=SCHEMA Set schema file path.
# --db-name-prefix=DB-NAME-PREFIX
# Set new database name prefix.
#
# -----------------------------------------------------------------------------
#
# usage: spool list [<flags>]
#
# Print databases.
#
# Flags:
# --help Show context-sensitive help (also try --help-long and
# --help-man).
# -p, --project=PROJECT Set GCP project ID. (use $SPANNER_PROJECT_ID or
# $GOOGLE_CLOUD_PROJECT as default value)
# -i, --instance=INSTANCE Set Cloud Spanner instance name. (use
# $SPANNER_INSTANCE_ID as default value)
# -d, --database=DATABASE Set Cloud Spanner database name. (use
# $SPOOL_SPANNER_DATABASE_ID as default value)
# -s, --schema=SCHEMA Set schema file path.
# --all Print databases. (without checksum filtering)
#
# -----------------------------------------------------------------------------
#
# usage: spool put <database>
#
# Return the database to the pool.
#
# Flags:
# --help Show context-sensitive help (also try --help-long and
# --help-man).
# -p, --project=PROJECT Set GCP project ID. (use $SPANNER_PROJECT_ID or
# $GOOGLE_CLOUD_PROJECT as default value)
# -i, --instance=INSTANCE Set Cloud Spanner instance name. (use
# $SPANNER_INSTANCE_ID as default value)
# -d, --database=DATABASE Set Cloud Spanner database name. (use
# $SPOOL_SPANNER_DATABASE_ID as default value)
# -s, --schema=SCHEMA Set schema file path.
#
# Args:
# <database> database name
#
# -----------------------------------------------------------------------------
#
# usage: spool clean [<flags>]
#
# Drop all idle databases.
#
# Flags:
# --help Show context-sensitive help (also try --help-long and
# --help-man).
# -p, --project=PROJECT Set GCP project ID. (use $SPANNER_PROJECT_ID or
# $GOOGLE_CLOUD_PROJECT as default value)
# -i, --instance=INSTANCE Set Cloud Spanner instance name. (use
# $SPANNER_INSTANCE_ID as default value)
# -d, --database=DATABASE Set Cloud Spanner database name. (use
# $SPOOL_SPANNER_DATABASE_ID as default value)
# -s, --schema=SCHEMA Set schema file path.
# --all Drop all idle databases. (without checksum filtering)
# --ignore-used-within-days=IGNORE-USED-WITHIN-DAYS
# Ignore databases which used within n days.
# --force Drop all databases. (include busy databases)
#
# -----------------------------------------------------------------------------
function _spool() {
local context curcontext=$curcontext state line expl ret=1
declare -A opt_args
local -a commands
commands=(
'help:Show help.'
'setup:Setup the database for spool metadata.'
'create:Add new databases to the pool.'
'get:Get a idle database from the pool.'
'get-or-create:Get or create a idle database from the pool.'
'list:Print databases.'
'put:Return the database to the pool.'
'clean:Drop all idle databases.'
)
_arguments -C \
'--help[Show context-sensitive help.]' \
{-p,--project}'=[Set GCP project ID. \(use $SPANNER_PROJECT_ID or $GOOGLE_CLOUD_PROJECT as default value\)]:project' \
{-i,--instance}'=[Set Cloud Spanner instance name. \(use $SPANNER_INSTANCE_ID as default value\)]:instance' \
{-d,--database}='[Set Cloud Spanner database name. \(use $SPOOL_SPANNER_DATABASE_ID as default value\)]:database' \
{-s,--schema}='[Set schema file path.]:schema:_files' \
"1: :{_describe 'spool commands' commands}" \
'*:: :->args' \
&& ret=0
case $words[1] in
setup)
_arguments \
'--help[Show context-sensitive help.]' \
{-p,--project}'=[Set GCP project ID. \(use $SPANNER_PROJECT_ID or $GOOGLE_CLOUD_PROJECT as default value\)]:project' \
{-i,--instance}'=[Set Cloud Spanner instance name. \(use $SPANNER_INSTANCE_ID as default value\)]:instance' \
{-d,--database}='[Set Cloud Spanner database name. \(use $SPOOL_SPANNER_DATABASE_ID as default value\)]:database' \
{-s,--schema}='[Set schema file path.]:schema:_files'
;;
create)
_arguments \
'--help[Show context-sensitive help.]' \
{-p,--project}'=[Set GCP project ID. \(use $SPANNER_PROJECT_ID or $GOOGLE_CLOUD_PROJECT as default value\)]:project' \
{-i,--instance}'=[Set Cloud Spanner instance name. \(use $SPANNER_INSTANCE_ID as default value\)]:instance' \
{-d,--database}='[Set Cloud Spanner database name. \(use $SPOOL_SPANNER_DATABASE_ID as default value\)]:database' \
{-s,--schema}='[Set schema file path.]:schema:_files' \
'--db-name-prefix=[Set new database name prefix.]:DB-NAME-PREFIX' \
'--num=[Set the number of new databases.]:number of databases'
;;
get)
_arguments \
'--help[Show context-sensitive help.]' \
{-p,--project}'=[Set GCP project ID. \(use $SPANNER_PROJECT_ID or $GOOGLE_CLOUD_PROJECT as default value\)]:project' \
{-i,--instance}'=[Set Cloud Spanner instance name. \(use $SPANNER_INSTANCE_ID as default value\)]:instance' \
{-d,--database}='[Set Cloud Spanner database name. \(use $SPOOL_SPANNER_DATABASE_ID as default value\)]:database' \
{-s,--schema}='[Set schema file path.]:schema:_files'
;;
get-or-create)
_arguments \
'--help[Show context-sensitive help.]' \
{-p,--project}'=[Set GCP project ID. \(use $SPANNER_PROJECT_ID or $GOOGLE_CLOUD_PROJECT as default value\)]:project' \
{-i,--instance}'=[Set Cloud Spanner instance name. \(use $SPANNER_INSTANCE_ID as default value\)]:instance' \
{-d,--database}='[Set Cloud Spanner database name. \(use $SPOOL_SPANNER_DATABASE_ID as default value\)]:database' \
{-s,--schema}='[Set schema file path.]:schema:_files' \
'--db-name-prefix=[Set new database name prefix.]:DB-NAME-PREFIX'
;;
list)
_arguments \
'--help[Show context-sensitive help.]' \
{-p,--project}'=[Set GCP project ID. \(use $SPANNER_PROJECT_ID or $GOOGLE_CLOUD_PROJECT as default value\)]:project' \
{-i,--instance}'=[Set Cloud Spanner instance name. \(use $SPANNER_INSTANCE_ID as default value\)]:instance' \
{-d,--database}='[Set Cloud Spanner database name. \(use $SPOOL_SPANNER_DATABASE_ID as default value\)]:database' \
{-s,--schema}='[Set schema file path.]:schema:_files' \
'--all[Print databases. \(without checksum filtering\)]'
;;
put)
_arguments \
'--help[Show context-sensitive help.]' \
{-p,--project}'=[Set GCP project ID. \(use $SPANNER_PROJECT_ID or $GOOGLE_CLOUD_PROJECT as default value\)]:project' \
{-i,--instance}'=[Set Cloud Spanner instance name. \(use $SPANNER_INSTANCE_ID as default value\)]:instance' \
{-d,--database}='[Set Cloud Spanner database name. \(use $SPOOL_SPANNER_DATABASE_ID as default value\)]:database' \
{-s,--schema}='[Set schema file path.]:schema:_files' \
'*:database name'
;;
clean)
_arguments \
'--help[Show context-sensitive help.]' \
{-p,--project}'=[Set GCP project ID. \(use $SPANNER_PROJECT_ID or $GOOGLE_CLOUD_PROJECT as default value\)]:project' \
{-i,--instance}'=[Set Cloud Spanner instance name. \(use $SPANNER_INSTANCE_ID as default value\)]:instance' \
{-d,--database}='[Set Cloud Spanner database name. \(use $SPOOL_SPANNER_DATABASE_ID as default value\)]:database' \
{-s,--schema}='[Set schema file path.]:schema:_files' \
'--all[Drop all idle databases. \(without checksum filtering\)]' \
'--ignore-used-within-days=[Ignore databases which used within n days.]:ignore used within days' \
'--force[Drop all databases. \(include busy databases\)]'
;;
help)
_arguments "1: :{_describe 'command' commands}"
;;
esac
return ret
}
_spool "$*"
# vim:ft=zsh:et:sts=2:sw=2