Move another System/exit
out of run
This commit is contained in:
parent
3e665a4141
commit
7c3b1b9864
2 changed files with 21 additions and 13 deletions
30
src/core.clj
30
src/core.clj
|
@ -53,7 +53,9 @@
|
||||||
:period "January 2024"
|
:period "January 2024"
|
||||||
:total-fees 66.67M})
|
: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)
|
(let [options (if (:demo options) (merge options demo-options) options)
|
||||||
{:keys [date period pay-receipt-no pay-invoice-no total-fees project]} 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
|
{: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/fees date period fees-receipt-no fees-invoice-no total-fees project records)
|
||||||
(import/retirement date period retirement-receipt-no retirement-invoice-no records))
|
(import/retirement date period retirement-receipt-no retirement-invoice-no records))
|
||||||
unmatched (unmatched-employees records project)]
|
unmatched (unmatched-employees records project)]
|
||||||
(when (seq unmatched)
|
[imported 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)))))
|
|
||||||
|
|
||||||
(defn -main [& args]
|
(defn -main
|
||||||
(let [{:keys [options errors summary]} (parse-opts args cli-options)]
|
"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)
|
(when (:help options)
|
||||||
(println summary)
|
(println summary)
|
||||||
(System/exit 0))
|
(System/exit 0))
|
||||||
|
@ -84,7 +85,14 @@
|
||||||
(str "The following errors occurred:\n\n"
|
(str "The following errors occurred:\n\n"
|
||||||
(str/join \newline errors)))
|
(str/join \newline errors)))
|
||||||
(System/exit 1))
|
(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
|
(comment
|
||||||
;; Examples to exercise the importer during development.
|
;; Examples to exercise the importer during development.
|
||||||
|
|
|
@ -4,5 +4,5 @@
|
||||||
[clojure.string :as str]))
|
[clojure.string :as str]))
|
||||||
|
|
||||||
(deftest demo-produces-output
|
(deftest demo-produces-output
|
||||||
(let [output (with-out-str (core/run {:demo true}))]
|
(let [[imported _] (core/run {:demo true})]
|
||||||
(is (not (str/blank? output)))))
|
(is (pos? (count imported)))))
|
||||||
|
|
Loading…
Add table
Reference in a new issue