Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
13 changes: 13 additions & 0 deletions src/elle_cli/cli.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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)))
Expand Down
11 changes: 11 additions & 0 deletions test/elle_cli/elle_cli_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down
Loading