diff options
author | Bryan Newbold <bnewbold@robocracy.org> | 2020-05-10 15:10:26 -0700 |
---|---|---|
committer | Bryan Newbold <bnewbold@robocracy.org> | 2020-05-10 15:10:26 -0700 |
commit | 406d6e316e68eff3470809259e7cfe405253eea9 (patch) | |
tree | 429c4cd88890387bddb79d7c58fddde50c963533 /rust | |
parent | 1eb7d77b5c468eea5b9baa96dbc2831b1ffa764d (diff) | |
download | fatcat-bnewbold-rust-gen-v5.tar.gz fatcat-bnewbold-rust-gen-v5.zip |
vendor in openapi-generator-cli.sh helper scriptbnewbold-rust-gen-v5
Diffstat (limited to 'rust')
-rw-r--r-- | rust/.gitignore | 1 | ||||
-rwxr-xr-x | rust/openapi-generator-cli.sh | 70 |
2 files changed, 71 insertions, 0 deletions
diff --git a/rust/.gitignore b/rust/.gitignore index 7988ddba..a3222e33 100644 --- a/rust/.gitignore +++ b/rust/.gitignore @@ -3,5 +3,6 @@ target/ bin/ fatcat-*.tar.gz fatcat-openapi/Cargo.toml.codegen +openapi-generator-cli*.jar !.cargo diff --git a/rust/openapi-generator-cli.sh b/rust/openapi-generator-cli.sh new file mode 100755 index 00000000..e39ee086 --- /dev/null +++ b/rust/openapi-generator-cli.sh @@ -0,0 +1,70 @@ +#!/usr/bin/env bash +#### +# Save as openapi-generator-cli on your PATH. chmod u+x. Enjoy. +# +# This script will query github on every invocation to pull the latest released version +# of openapi-generator. +# +# If you want repeatable executions, you can explicitly set a version via +# OPENAPI_GENERATOR_VERSION +# e.g. (in Bash) +# export OPENAPI_GENERATOR_VERSION=3.1.0 +# openapi-generator-cli.sh +# or +# OPENAPI_GENERATOR_VERSION=3.1.0 openapi-generator-cli.sh +# +# This is also helpful, for example, if you want want to evaluate a SNAPSHOT version. +# +# NOTE: Jars are downloaded on demand from maven into the same directory as this script +# for every 'latest' version pulled from github. Consider putting this under its own directory. +#### +set -o pipefail + +for cmd in {mvn,jq,curl}; do + if ! command -v ${cmd} > /dev/null; then + >&2 echo "This script requires '${cmd}' to be installed." + exit 1 + fi +done + +function latest.tag { + local uri="https://api.github.com/repos/${1}/releases" + local ver=$(curl -s ${uri} | jq -r 'first(.[]|select(.prerelease==false)).tag_name') + if [[ $ver == v* ]]; then + ver=${ver:1} + fi + echo $ver +} + +ghrepo=openapitools/openapi-generator +groupid=org.openapitools +artifactid=openapi-generator-cli +ver=${OPENAPI_GENERATOR_VERSION:-$(latest.tag $ghrepo)} + +jar=${artifactid}-${ver}.jar +cachedir=${OPENAPI_GENERATOR_DOWNLOAD_CACHE_DIR} + +DIR=${cachedir:-"$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"} + +if [ ! -d "${DIR}" ]; then + mkdir -p "${DIR}" +fi + +if [ ! -f ${DIR}/${jar} ]; then + repo="central::default::https://repo1.maven.org/maven2/" + if [[ ${ver} =~ ^.*-SNAPSHOT$ ]]; then + repo="central::default::https://oss.sonatype.org/content/repositories/snapshots" + fi + mvn org.apache.maven.plugins:maven-dependency-plugin:2.9:get \ + -DremoteRepositories=${repo} \ + -Dartifact=${groupid}:${artifactid}:${ver} \ + -Dtransitive=false \ + -Ddest=${DIR}/${jar} +fi + +java -ea \ + ${JAVA_OPTS} \ + -Xms512M \ + -Xmx1024M \ + -server \ + -jar ${DIR}/${jar} "$@" |