generated from octomation/go-tool
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Taskfile
executable file
·89 lines (76 loc) · 1.63 KB
/
Taskfile
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
#!/usr/bin/env bash
[ "${BASH_VERSINFO:-0}" -ge 4 ] || {
echo "bash version 4 or higher is required" >&2
exit 1
}
set -euo pipefail
declare -A config
config['dryrun']=false
function github() {
_ mod upgrade -t "${1}" --mod-name=github.com/google/go-github/v"$(($1 - 1))"
_ go mod tidy
_ make format
}
function testdata() {
local base='https://github.com/kamilsk?controller=profiles&action=show&tab=contributions'
declare -A urls
urls['kamilsk.1986.html']="${base}&from=1986-01-01"
urls['kamilsk.2019.html']="${base}&from=2019-01-01"
urls['kamilsk.2021.html']="${base}&from=2021-01-01"
for name in "${!urls[@]}"; do
_ curl -sSfL -H 'X-Requested-With: XMLHttpRequest' "${urls[${name}]}" \
> "internal/model/github/contribution/testdata/${name}"
done
}
@debug() { echo "${@}"; }
@trace() { @debug "${@}" && "${@}"; }
@error() { echo "${@}" >&2; }
@fatal() { @error "${@}" && exit 1; }
@usage() {
cat - <<EOF
Usage: $0 <task> <args>
Tasks:
EOF
compgen -A function | grep -Ev '^(@|_)' | sort | cat -n
}
@() {
${config['dryrun']} && echo "${@}"
"${@}"
}
_() {
if ${config['dryrun']}; then
echo "${@}"
return
fi
trap 'echo "${@}"' ERR
"${@}"
}
-() {
if ${config['dryrun']}; then
echo "${*} || false"
return
fi
trap 'echo "${*} || false"' ERR
"${@}" || false
}
+() {
if ${config['dryrun']}; then
echo "${*} || true"
return
fi
trap 'echo "${*} || true"' ERR
"${@}" || true
}
function @main() {
for arg in "${@}"; do
case "${arg}" in
-d | --dry-run)
config['dryrun']=true
shift
;;
*) break ;;
esac
done
"${@:-@usage}"
}
@main "${@}"