From 8c1dd97a8c94b9b1c11fbbe2d60cbac32a1eea1d Mon Sep 17 00:00:00 2001 From: Ben Sturmfels Date: Fri, 16 May 2025 16:31:56 +1000 Subject: [PATCH] Validate that the CSV file exists --- README.md | 8 ++++---- TODO.md | 1 - src/core.clj | 5 +++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 572b7d0..6133f54 100644 --- a/README.md +++ b/README.md @@ -14,17 +14,17 @@ This program requires a Java runtime environment (tested with OpenJDK 17 and Run a demo with two example employees, Jack and Jill Citizen: - java -jar import-x.x.x-standalone.jar --demo + java -jar payroll-importer-x.x.x-standalone.jar --demo Provide your own payroll data with: - java -jar import-x.x.x-standalone.jar --csv resources/example-paychex-pay-item-details.csv --total-fees 206.50 + java -jar payroll-importer-x.x.x-standalone.jar --csv resources/example-paychex-pay-item-details.csv --total-fees 206.50 In the above, various values such as the date, time period covered and receipt/invoice values show "TODO" placeholders that you are expected to fill in later. If you prefer, you can provide any/all of these explicitly: - java -jar import-x.x.x-standalone.jar --csv resources/example-paychex-pay-item-details.csv --date 2023-12-29 --period 'December 2023' --total-fees 206.50 --pay-receipt-no rt:19462/674660 --pay-invoice-no rt:19403/675431 --fees-receipt-no rt:19459/675387 --fees-invoice-no rt:19459/674887 --retirement-receipt-no rt:19403/676724 --retirement-invoice-no rt:19403/675431 + java -jar payroll-importer-x.x.x-standalone.jar --csv resources/example-paychex-pay-item-details.csv --date 2023-12-29 --period 'December 2023' --total-fees 206.50 --pay-receipt-no rt:19462/674660 --pay-invoice-no rt:19403/675431 --fees-receipt-no rt:19459/675387 --fees-invoice-no rt:19459/674887 --retirement-receipt-no rt:19403/676724 --retirement-invoice-no rt:19403/675431 You can test the output in Beancount by adding the following header entries to define the accounts: @@ -52,7 +52,7 @@ To build, run: bin/build -This will output a JAR file like `target/import-x.x.x-standalone.jar`, where the +This will output a JAR file like `target/payroll-importer-x.x.x-standalone.jar`, where the version number is based on the Git revision. diff --git a/TODO.md b/TODO.md index ac76ed7..b5a44fa 100644 --- a/TODO.md +++ b/TODO.md @@ -1,6 +1,5 @@ # To-do * Avoid hard-coding the bank account -* Add validation/error handling of required CLI arguments such as csv, date and period * Potentially move employee-name->entity-tag into config * Potentially move cat->payroll-type into config diff --git a/src/core.clj b/src/core.clj index ac4c594..35a0bbe 100644 --- a/src/core.clj +++ b/src/core.clj @@ -11,7 +11,8 @@ (:gen-class)) (def cli-options - [[nil "--csv FILE" "Pay Item Details CSV report"] + [[nil "--csv FILE" "Pay Item Details CSV report" + :validate [#(-> % io/file .exists) "File does not exist"]] [nil "--date DATE" "Date used for the transactions (YYYY-MM-DD)" :validate [#(re-matches #"\d{4}-\d{2}-\d{2}" %) "Must be of format YYYY-MM-DD"] :default "TODO-DATE"] @@ -60,7 +61,7 @@ (System/exit 0)) (when errors (println - (str "The following errors occurred while parsing your command:\n\n" + (str "The following errors occurred:\n\n" (str/join \newline errors))) (System/exit 1)) (let [{:keys [date period pay-receipt-no pay-invoice-no total-fees project]} options