Skip to content

Commit

Permalink
Fix exit code when history is not valid
Browse files Browse the repository at this point in the history
Patch changes exit code to 1 when at least one file with history is not
valid.

Fixes #53
  • Loading branch information
ligurio committed Jun 30, 2022
1 parent 620f3fe commit 631b968
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ change log follows the conventions of
### Fixed

- Fix setting of headless mode (#50).
- Fix exit code when history is not valid (#53).

### Changed

Expand Down
13 changes: 10 additions & 3 deletions src/elle_cli/cli.clj
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,16 @@
(let [ext (second (re-find #"\.([a-zA-Z0-9]+)$" filepath))]
(get history-read-fn ext)))

(defn lazy-contains? [coll key]
(boolean (some #(= % key) coll)))

(defn -main
[& args]
(try
(let [{:keys [options arguments summary errors]} (cli/parse-opts args opts)
model-name (:model options)
read-history (:format options)
results (atom (hash-map))
help (:help options)]
(when-not (empty? errors)
(doseq [e errors]
Expand All @@ -223,13 +227,16 @@

(let [read-history (or read-history (read-fn-by-extension filepath))
history (read-history filepath)
analysis (check-history model-name history options)]
analysis (check-history model-name history options)
validness (:valid? analysis)]

(swap! results assoc filepath validness)

(if (true? (:verbose options))
(json/pprint analysis)
(println filepath "\t" (:valid? analysis)))))
(println filepath "\t" validness))))

(System/exit 0))
(System/exit ({true 1 false 0} (lazy-contains? (vals @results) false))))

(catch Throwable t
(println)
Expand Down
6 changes: 4 additions & 2 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ run_test() {
test_status="NOT OK"
cmd="$ELLE_CLI_BIN $elle_cli_opts"
test_output=$($cmd)
rc=$?
res=$(echo $test_output | cut -d" " -f2)
if { [ "X$res" = Xfalse ] && [ "$exit_code" -ne 0 ]; } ||
{ [ "X$res" = Xtrue ] && [ "$exit_code" -eq 0 ]; }; then
if { { [ "X$res" = Xfalse ] && [ "$exit_code" -ne 0 ]; } ||
{ [ "X$res" = Xtrue ] && [ "$exit_code" -eq 0 ]; }; } &&
[ "$exit_code" -eq $rc ]; then
test_status="OK"
else
suite_status=1
Expand Down

0 comments on commit 631b968

Please sign in to comment.