From 7c3b1b98642a9db52bec73db3366c974c6590766 Mon Sep 17 00:00:00 2001 From: Ben Sturmfels Date: Sat, 20 Sep 2025 00:54:48 +1000 Subject: [PATCH] Move another `System/exit` out of `run` --- src/core.clj | 30 +++++++++++++++++++----------- test/core_test.clj | 4 ++-- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/core.clj b/src/core.clj index 5257e1d..897d272 100644 --- a/src/core.clj +++ b/src/core.clj @@ -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. diff --git a/test/core_test.clj b/test/core_test.clj index c9b6032..78d749e 100644 --- a/test/core_test.clj +++ b/test/core_test.clj @@ -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)))))