Move another System/exit out of run

This commit is contained in:
Ben Sturmfels 2025-09-20 00:54:48 +10:00
parent 3e665a4141
commit 7c3b1b9864
Signed by: bsturmfels
GPG key ID: 023C05E2C9C068F0
2 changed files with 21 additions and 13 deletions

View file

@ -53,7 +53,9 @@
:period "January 2024"
:total-fees 66.67M})
(defn run [options]
(defn run
"Run the import with a map of options."
[options]
(let [options (if (:demo options) (merge options demo-options) options)
{:keys [date period pay-receipt-no pay-invoice-no total-fees project]} options
{:keys [fees-receipt-no fees-invoice-no retirement-receipt-no retirement-invoice-no]} options
@ -66,16 +68,15 @@
(import/fees date period fees-receipt-no fees-invoice-no total-fees project records)
(import/retirement date period retirement-receipt-no retirement-invoice-no records))
unmatched (unmatched-employees records project)]
(when (seq unmatched)
(println
(str "Could not find these employees in the payroll:\n\n"
(str/join ", " unmatched)))
(System/exit 1))
(doseq [i imported]
(println (import/render-transaction i)))))
[imported unmatched]))
(defn -main [& args]
(let [{:keys [options errors summary]} (parse-opts args cli-options)]
(defn -main
"Run the CLI interface."
[& args]
(let [{:keys [options errors summary]} (parse-opts args cli-options)
errors (if-not (or (contains? options :csv) (contains? options :demo))
(conj errors "Please provide a CSV file with \"--csv FILE\" or try \"--demo\"")
errors)]
(when (:help options)
(println summary)
(System/exit 0))
@ -84,7 +85,14 @@
(str "The following errors occurred:\n\n"
(str/join \newline errors)))
(System/exit 1))
(run options)))
(let [[imported unmatched] (run options)]
(when (seq unmatched)
(println
(str "Could not find these employees in the payroll:\n\n"
(str/join ", " unmatched)))
(System/exit 1))
(doseq [i imported]
(println (import/render-transaction i))))))
(comment
;; Examples to exercise the importer during development.

View file

@ -4,5 +4,5 @@
[clojure.string :as str]))
(deftest demo-produces-output
(let [output (with-out-str (core/run {:demo true}))]
(is (not (str/blank? output)))))
(let [[imported _] (core/run {:demo true})]
(is (pos? (count imported)))))