2016-05-25 03:21:50 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
|
|
|
# GEN_DIR allows to share the entrypoint between Dockerfile and run-in-docker.sh (backward compatible)
|
2018-04-17 07:19:10 +00:00
|
|
|
GEN_DIR=${GEN_DIR:-/opt/openapi-generator}
|
2016-05-25 03:21:50 +00:00
|
|
|
JAVA_OPTS=${JAVA_OPTS:-"-Xmx1024M -DloggerPath=conf/log4j.properties"}
|
|
|
|
|
2018-04-17 07:19:10 +00:00
|
|
|
cli="${GEN_DIR}/modules/openapi-generator-cli"
|
|
|
|
codegen="${cli}/target/openapi-generator-cli.jar"
|
2016-05-25 03:21:50 +00:00
|
|
|
|
2018-06-10 11:33:00 +00:00
|
|
|
# We code in a list of commands here as source processing is potentially buggy (requires undocumented conventional use of annotations).
|
|
|
|
# A list of known commands helps us determine if we should compile CLI. There's an edge-case where a new command not added to this
|
|
|
|
# list won't be considered a "real" command. We can get around that a bit by checking CLI completions beforehand if it exists.
|
2019-01-07 13:57:05 +00:00
|
|
|
commands="list,generate,meta,help,config-help,validate,version"
|
2018-06-10 11:33:00 +00:00
|
|
|
|
|
|
|
# if CLI jar exists, check $1 against completions available in the CLI
|
|
|
|
if [[ -f "${codegen}" && -n "$(java ${JAVA_OPTS} -jar "${codegen}" completion | grep "^$1\$" )" ]]; then
|
|
|
|
command=$1
|
|
|
|
shift
|
|
|
|
exec java ${JAVA_OPTS} -jar "${codegen}" "${command}" "$@"
|
2019-07-18 05:22:12 +00:00
|
|
|
elif [[ -n "$(echo $commands | tr ',' '\n' | grep "^$1\$" )" ]]; then
|
2018-06-10 11:33:00 +00:00
|
|
|
# If CLI jar does not exist, and $1 is a known CLI command, build the CLI jar and run that command.
|
2017-05-08 10:12:13 +00:00
|
|
|
if [[ ! -f "${codegen}" ]]; then
|
2018-05-30 22:56:08 +00:00
|
|
|
(cd "${GEN_DIR}" && exec mvn -am -pl "modules/openapi-generator-cli" -Duser.home=$(dirname $MAVEN_CONFIG) package)
|
2017-05-08 10:12:13 +00:00
|
|
|
fi
|
|
|
|
command=$1
|
|
|
|
shift
|
|
|
|
exec java ${JAVA_OPTS} -jar "${codegen}" "${command}" "$@"
|
|
|
|
else
|
2018-06-10 11:33:00 +00:00
|
|
|
# Pass args as linux commands. This allows us to do something like: docker run -it (-e…, -v…) image ls -la
|
2017-05-08 10:12:13 +00:00
|
|
|
exec "$@"
|
|
|
|
fi
|