-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmulle-domain
executable file
·364 lines (283 loc) · 9.69 KB
/
mulle-domain
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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
#! /usr/bin/env mulle-bash
# shellcheck shell=bash
#
# Copyright (c) 2015-2017 Nat! - Mulle kybernetiK
# 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 Mulle kybernetiK 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.
#
[ "${TRACE:-}" = 'YES' -o "${MULLE_DOMAIN_TRACE:-}" = 'YES' ] && set -x && : "${MULLE_EXCUTABLE}" "$@"
MULLE_EXECUTABLE_VERSION="1.5.3"
#
# Determine location of own libexec directory. Which is `src` in development
# and ../libexec when deployed. MULLE_EXECUTABLE needs to be defined for this.
#
if ! [ ${MULLE_DOMAIN_LIBEXEC_DIR+x} ]
then
r_get_libexec_dir "${MULLE_EXECUTABLE}" "mulle-domain" "mulle-domain-compose.sh"
MULLE_DOMAIN_LIBEXEC_DIR="${RVAL}"
fi
set +u
#
# This is the domain::main user interface to mulle-domain
# sorta like git
#
domain::print_commands()
{
local show_all="${1:-NO}"
SHOWN_COMMANDS="\
compose-url : create an URL
nameguess : guess final filename from url, (hint: specify -s <scm>)
parse-url : parse an URL
resolve : get tag that matches a semver qualifier best
tags : list all tags of a repository
tags-with-commits : list tags with commit identifiers in alternate lines
list : list known repository domains for which a plugin exists"
HIDDEN_COMMANDS="\
libexec-dir : print path to mulle-domain libexec
typeguess : guess plugin name suitable for url
commit-for-tag : given a tag get the commit identifier
tags-for-commit : list all tags that reference the given commit identifier
tag-aliases : list all tags that reference the same tag
uname : mulle-domains simplified uname(1)
version : print mulle-domain version"
printf "%s\n" "${SHOWN_COMMANDS}"
if [ "${show_all}" != 'NO' ]
then
printf "%s\n" "${HIDDEN_COMMANDS}"
fi
}
domain::print_flags()
{
cat <<EOF
--domain-token <token> : sets MULLE_DOMAIN_<domain>_TOKEN (see Environment)
--per-page <value> : sets MULLE_DOMAIN_<domain>_PER_PAGE
--max-pages <value> : sets MULLE_DOMAIN_<domain>_MAX_PAGES
--user <name> : username for the given domain
--repo <name> : repository name
EOF
if [ "${verbose}" = 'YES' ]
then
cat <<EOF
-h : this help
EOF
options_technical_flags_usage " : "
fi
}
domain::do_usage()
{
local verbose="${1:-NO}"
cat <<EOF
Usage:
${MULLE_USAGE_NAME} [flags] <command>
Parse or compose source code repository URLs. Guesses project names from a
given URL. Access tag information from a repository hosted on known domains
(e.g. "github").
Examples:
mulle-domain nameguess \\
https://github.com/mulle-objc/MulleObjC/archive/refs/tags/0.19.0.zip
mulle-domain parse-url \\
https://github.com/openssl/openssl/archive/OpenSSL_1_0_2u.tar.gz
EOF
cat <<EOF
Commands:
EOF
domain::print_commands "${verbose}" | LC_ALL=C sort
if [ "${verbose}" = 'NO' ]
then
cat <<EOF
(Use mulle-domain -v help for more commands)
EOF
fi
cat <<EOF
(Use mulle-domain <command> -h for command specific help.)
EOF
echo
echo "Flags:"
domain::print_flags "${verbose}" | LC_ALL=C sort
cat <<EOF
Environment:
MULLE_DOMAIN_<domain>_TOKEN : access token to use, domain in uppercase
MULLE_DOMAIN_<domain>_MAX_PAGES : max pages to domain (20)
MULLE_DOMAIN_<domain>_PER_PAGE : number of entries per page up to 100 (100)
EOF
}
domain::usage()
{
domain::do_usage "$@" >&2
exit 1
}
domain::main()
{
local MULLE_FLAG_MAGNUM_FORCE='NO'
# technical flags
local MULLE_TRACE
local MULLE_FLAG_EXEKUTOR_DRY_RUN='NO'
local MULLE_FLAG_LOG_LOCAL='NO'
local MULLE_FLAG_LOG_DEBUG='NO'
local MULLE_FLAG_LOG_EXEKUTOR='NO'
local MULLE_FLAG_LOG_FLUFF='NO'
local MULLE_FLAG_LOG_SCRIPTS='NO'
local MULLE_FLAG_LOG_SETTINGS='NO'
local MULLE_FLAG_LOG_VERBOSE='NO'
local MULLE_FLAG_LOG_MERGE='NO'
local MULLE_TRACE_POSTPONE='NO'
#
# simple option handling
#
while [ $# -ne 0 ]
do
if options_technical_flags "$1"
then
shift
continue
fi
case "$1" in
-h*|--help|help)
domain::usage "${MULLE_TRACE}"
;;
--github|--github-user)
[ $# -eq 1 ] && fail "Missing argument to \"$1\""
shift
OPTION_GITHUB_USER="$1"
;;
--git-terminal-prompt)
[ $# -eq 1 ] && fail "Missing argument to \"$1\""
shift
GIT_TERMINAL_PROMPT="$1"
export GIT_TERMINAL_PROMPT
;;
--version)
printf "%s\n" "${MULLE_EXECUTABLE_VERSION}"
exit 0
;;
-*)
log_error "Unknown option \"$1\""
domain::usage "${MULLE_TRACE}"
;;
*)
break
;;
esac
shift
done
options_setup_trace "${MULLE_TRACE}" && set -x
include "url"
local cmd="$1"
[ $# -eq 0 ] || shift
case "${cmd}" in
""|'help')
domain::usage
;;
'homepage-url')
# shellcheck source=src/mulle-domain-compose.sh
. "${MULLE_DOMAIN_LIBEXEC_DIR}/mulle-domain-parse.sh"
. "${MULLE_DOMAIN_LIBEXEC_DIR}/mulle-domain-compose.sh"
domain::parse::main "$@" | domain::compose::main - --scm homepage
;;
'compose'|'compose-url'|'url-compose')
# shellcheck source=src/mulle-domain-compose.sh
. "${MULLE_DOMAIN_LIBEXEC_DIR}/mulle-domain-compose.sh"
domain::compose::main "$@"
;;
'commit-for-tag')
# shellcheck source=src/mulle-domain-commands.sh
. "${MULLE_DOMAIN_LIBEXEC_DIR}/mulle-domain-commands.sh"
domain::commands::commit_for_tag_main "$@"
;;
'libexec-dir'|'library-path')
printf "%s\n" "${MULLE_DOMAIN_LIBEXEC_DIR}"
;;
'list')
# shellcheck source=src/mulle-domain-plugin.sh
. "${MULLE_DOMAIN_LIBEXEC_DIR}/mulle-domain-plugin.sh"
domain::plugin::main "$@" list
;;
'nameguess'|'guess'|'guess-name'|'name-guess')
# shellcheck source=src/mulle-domain-guess.sh
. "${MULLE_DOMAIN_LIBEXEC_DIR}/mulle-domain-guess.sh"
domain::guess::nameguess_main "$@"
;;
'parse'|'parse-url'|'url-parse')
# shellcheck source=src/mulle-domain-parse.sh
. "${MULLE_DOMAIN_LIBEXEC_DIR}/mulle-domain-parse.sh"
domain::parse::main "$@"
;;
'plugin')
# shellcheck source=src/mulle-domain-commands.sh
. "${MULLE_DOMAIN_LIBEXEC_DIR}/mulle-domain-plugin.sh"
domain::plugin::main "$@"
;;
'resolve')
# shellcheck source=src/mulle-domain-resolve.sh
. "${MULLE_DOMAIN_LIBEXEC_DIR}/mulle-domain-resolve.sh"
domain::resolve::main "$@"
;;
'tags')
# shellcheck source=src/mulle-domain-commands.sh
. "${MULLE_DOMAIN_LIBEXEC_DIR}/mulle-domain-commands.sh"
domain::commands::main "$@"
;;
'tag-exists')
# shellcheck source=src/mulle-domain-commands.sh
. "${MULLE_DOMAIN_LIBEXEC_DIR}/mulle-domain-commands.sh"
domain_tag_exists_main "$@"
;;
'tags-with-commits')
# shellcheck source=src/mulle-domain-commands.sh
. "${MULLE_DOMAIN_LIBEXEC_DIR}/mulle-domain-commands.sh"
domain::commands::tags_with_commits_main "$@"
;;
'tags-for-commit')
# shellcheck source=src/mulle-domain-commands.sh
. "${MULLE_DOMAIN_LIBEXEC_DIR}/mulle-domain-commands.sh"
domain::commands::tags_for_commit_main "$@"
;;
'tag-aliases')
# shellcheck source=src/mulle-domain-commands.sh
. "${MULLE_DOMAIN_LIBEXEC_DIR}/mulle-domain-commands.sh"
domain::commands::get_tag_aliases_main "$@"
;;
'typeguess'|'type-guess'|'guess-type')
# shellcheck source=src/mulle-domain-guess.sh
. "${MULLE_DOMAIN_LIBEXEC_DIR}/mulle-domain-guess.sh"
domain::guess::typeguess_main "$@"
;;
'uname')
printf "%s\n" "${MULLE_UNAME}"
;;
'version')
printf "%s\n" "${MULLE_EXECUTABLE_VERSION}"
return 0
;;
*)
log_error "Unknown command \"${cmd}\""
domain::usage
;;
esac
}
call_with_flags "domain::main" "${MULLE_DOMAIN_FLAGS}" "$@"