diff --git a/CHANGELOG.md b/CHANGELOG.md index 75cff10..6f647fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ change log follows the conventions of ### Added +- An option `--version` that prints the elle-cli version and exits. + ### Changed - Report a proper error for an unknown model name (#100). diff --git a/src/elle_cli/cli.clj b/src/elle_cli/cli.clj index ad01efe..877a16d 100644 --- a/src/elle_cli/cli.clj +++ b/src/elle_cli/cli.clj @@ -42,6 +42,13 @@ h )) +(defn version + "Return the elle-cli version from the pom.properties embedded by + Leiningen at build time." + [] + (when-let [r (io/resource "META-INF/maven/elle-cli/elle-cli/pom.properties")] + (second (re-find #"(?m)^version=(.*)$" (slurp r))))) + (defn vl [v] (if (string? v) @@ -109,6 +116,8 @@ :validate [#{:text :json} "Must be one of text, json"]] ["-h" "--help" "(General) Print usage."] + [nil "--version" + "(General) Print version and exit."] ; Elle-specific options. ["-c" "--consistency-models CONSISTENCY-MODELS" @@ -231,6 +240,10 @@ (println e)) (System/exit 1)) + (when (:version options) + (println (str "elle-cli " (version))) + (System/exit 0)) + (if (or (nil? model-name) (true? help)) ( (println (usage summary)) (System/exit 0))) diff --git a/test/elle_cli/elle_cli_test.clj b/test/elle_cli/elle_cli_test.clj index 8fc5a34..6a57894 100644 --- a/test/elle_cli/elle_cli_test.clj +++ b/test/elle_cli/elle_cli_test.clj @@ -7,6 +7,7 @@ [clojure.java.io :as io] [clojure.data.json :as json] [jepsen.history :as h] + [clojure.tools.cli :as tools-cli] [elle_cli.cli :as cli])) (def data-dir @@ -275,6 +276,16 @@ (is (.exists expected) (str "generated expected result: " (.getPath expected))))))) +(deftest check-version-option + (testing "--version is parsed without errors" + (let [{:keys [options errors]} (tools-cli/parse-opts ["--version"] cli/opts)] + (is (nil? errors)) + (is (true? (:version options))))) + (testing "version is reported in the MAJOR.MINOR.PATCH format" + (let [v (cli/version)] + (is (some? v)) + (is (re-matches #"\d+\.\d+\.\d+" v))))) + (deftest check-histories (doseq [[model cases] model-cases case cases]