-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate.sh
executable file
·61 lines (53 loc) · 2.26 KB
/
generate.sh
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
#!/usr/bin/env bash
GENERATOR_IMAGE=registry.gitlab.com/tokend/openapi-go-generator:2a569da8480b7c63cae4fe43363ddc99fd2e9eda # latest generator commit in master
GENERATED="${GOPATH}/src/gitlab.com/tokend/regources/generated"
OPENAPI_DIR="${GOPATH}/src/gitlab.com/tokend/horizon/docs/build"
PACKAGE_NAME=regources
function printHelp {
echo "usage: ./generate.sh [<flags>] [<args> ...]
script to generate regources for horizon
Flags:
--package PACKAGE package name of generated stuff (first line of file)
--image IMAGE name of generator docker image (default is openapi-generator)
-h, --help Show this help.
-v, --to-vendor put generated output to vendor dir
-p, --path-to-generate PATH path to put generated things
-i, --input OPENAPI_DIR path to dir where openapi.yaml is stored (default horizon/docs/build for horizon)"
}
function parseArgs {
while [[ -n "$1" ]]
do
case "$1" in
-h | --help)
printHelp && exit 0
;;
-v | --to-vendor)
GENERATED="${GOPATH}/src/gitlab.com/tokend/horizon/vendor/gitlab.com/tokend/regources/generated"
;;
-p | --path-to-generate) shift
[[ ! -d $1 ]] && echo "path $1 does not exist or not a dir" && exit 1
GENERATED=$1
;;
--package) shift
[[ ! -z "$1" ]] && echo "package name not specified" && exit 1
PACKAGE_NAME=$1
;;
-i | --input) shift
[[ ! -f "$1/openapi.yaml" ]] && echo "file openapi.yaml does not exist in $1 or not a file" && exit 1
OPENAPI_DIR=$1
;;
--image) shift
[[ "$(docker images -q $1)" == "" ]] && echo "image $1 does not exist locally" && exit 1
GENERATOR_IMAGE=$1
;;
esac
shift
done
}
function generate {
(cd docs && make)
docker run -v ${OPENAPI_DIR}:/openapi -v ${GENERATED}:/generated ${GENERATOR_IMAGE} generate --generate-horizon-stuff --meta-for-lists
goimports -w ${GENERATED}
}
parseArgs $@
generate