Skip to content

Commit

Permalink
Provide --version option
Browse files Browse the repository at this point in the history
  • Loading branch information
joodie committed Jan 30, 2024
1 parent b42a488 commit 77d4752
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
/share/
/target/
*.jar
/src/nl/jomco/apie/version.txt
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -35,9 +36,12 @@ 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
$(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
Expand Down
20 changes: 16 additions & 4 deletions src/nl/jomco/apie/main.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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.
Expand Down Expand Up @@ -127,14 +136,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)
Expand Down

0 comments on commit 77d4752

Please sign in to comment.