From 4d838750bf409f708e94e09bcb1ef76f473f39b3 Mon Sep 17 00:00:00 2001 From: Nate Jones Date: Sat, 13 Jun 2020 15:02:31 -0700 Subject: [PATCH] Add support for reporting version --- resources/VERSION | 1 + scripts/compile | 1 + src/brisk/lib/opts.clj | 4 ++-- src/brisk/main.clj | 7 +++++++ 4 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 resources/VERSION diff --git a/resources/VERSION b/resources/VERSION new file mode 100644 index 0000000..b694fe3 --- /dev/null +++ b/resources/VERSION @@ -0,0 +1 @@ +0.1.0-SNAPSHOT diff --git a/scripts/compile b/scripts/compile index 0970b43..e684452 100755 --- a/scripts/compile +++ b/scripts/compile @@ -17,6 +17,7 @@ $NATIVE_IMAGE \ -H:Name=$app_name \ -H:+ReportExceptionStackTraces \ -H:ReflectionConfigurationFiles=reflection.json \ + -H:IncludeResources=VERSION \ --initialize-at-build-time \ --report-unsupported-elements-at-runtime \ --verbose \ diff --git a/src/brisk/lib/opts.clj b/src/brisk/lib/opts.clj index f966ac0..28899fe 100644 --- a/src/brisk/lib/opts.clj +++ b/src/brisk/lib/opts.clj @@ -31,8 +31,8 @@ (defn format-help [progname help parsed errors] (let [{:keys [summary]} parsed - {:keys [message exit]} errors] - {:help (format help-fmt progname (or message help) summary) + {:keys [message plain exit]} errors] + {:help (if plain message (format help-fmt progname (or message help) summary)) :exit exit})) (defn print-and-exit diff --git a/src/brisk/main.clj b/src/brisk/main.clj index 229f903..4789ef2 100644 --- a/src/brisk/main.clj +++ b/src/brisk/main.clj @@ -2,6 +2,7 @@ (:require [clojure.edn :as edn] [clojure.java.io :as io] + [clojure.string :as string] [clojure.tools.cli :refer [parse-opts]] [taoensso.nippy :as nippy] @@ -65,6 +66,7 @@ ["-t" "--thaw" "Thaw mode"] ["-i" "--input FILENAME" "Input file"] ["-o" "--output FILENAME" "Output file"] + ["-v" "--version" "Print version"] ]) (def help @@ -81,6 +83,11 @@ (or (opts/find-errors parsed) (let [{:keys [options]} parsed] (cond + (:version options) + {:message (string/trim (slurp (io/resource "VERSION"))) + :plain true + :exit 0} + (and (not (:thaw options)) (not (:freeze options))) {:exit 1}))))