From 002ee4f7184130ae3a7e036d612f6d464aabceb1 Mon Sep 17 00:00:00 2001 From: Joost Diepenmaat Date: Tue, 30 Jan 2024 16:30:30 +0100 Subject: [PATCH] Provide --version option --- .gitignore | 1 + Makefile | 9 ++++++++- src/nl/jomco/apie/main.clj | 20 ++++++++++++++++---- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index a6abc0c..15ac4f5 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ /share/ /target/ *.jar +/src/nl/jomco/apie/version.txt diff --git a/Makefile b/Makefile index 6ef47c9..e4bebd8 100644 --- a/Makefile +++ b/Makefile @@ -19,11 +19,12 @@ BB:=bb version:=$(shell git describe --tags) +baked_version:=$(shell cat "src/nl/jomco/apie/version.txt") # need latest snapshot for standalone executables BABASHKA_VERSION:=1.3.188 -.PHONY: uberjar +.PHONY: uberjar bake-version exec_base_name=apie release_name=$(exec_base_name)-$(version) @@ -35,10 +36,16 @@ uberjar=$(exec_base_name)-$(version)-standalone.jar uberjar: $(uberjar) + $(uberjar): deps.edn bb.edn $(source_files) + +$(uberjar): deps.edn bb.edn $(source_files) bake-version rm -f $@ $(BB) uberjar $@ -m nl.jomco.apie.main +bake-version: + if [ "$(version)" != "$(baked_version)" ]; then echo "$(version)" >src/nl/jomco/apie/version.txt; fi + release: $(binary_release) # for unixy systems diff --git a/src/nl/jomco/apie/main.clj b/src/nl/jomco/apie/main.clj index a787f58..831bbd1 100644 --- a/src/nl/jomco/apie/main.clj +++ b/src/nl/jomco/apie/main.clj @@ -55,6 +55,9 @@ "Maximum number of requests per operation in OpenAPI spec." :default ##Inf :parse-fn parse-long] + ["-v" "--version" + "Print version and exit." + :id :print-version?] ["-a" "--basic-auth 'USER:PASS'" "Send basic authentication header." :default nil :parse-fn (fn [s] @@ -64,6 +67,12 @@ {:user user :pass pass}))]]) +(defn version + "Return app version" + [] + (when-let [r (io/resource "nl/jomco/apie/version.txt")] + (string/trim (slurp r)))) + (defn file-or-resource "Return f as file if it exists, otherwise as resource. @@ -128,14 +137,17 @@ spec-data (if parent-dir (read-json (io/file parent-dir openapi-spec)) (read-json (file-or-resource openapi-spec)))] - (when-not no-spider? - (spider spec-data profile-data options)) - (when-not no-report? - (report spec-data options)))) + (when-not no-spider? + (spider spec-data profile-data options)) + (when-not no-report? + (report spec-data options)))) (defn -main [& args] (let [{:keys [errors summary options]} (parse-opts args cli-options)] + (when (:print-version? options) + (println (version)) + (System/exit 0)) (when (seq errors) (run! println errors) (println summary)