Validate that the CSV file exists

This commit is contained in:
Ben Sturmfels 2025-05-16 16:31:56 +10:00
parent d61f910608
commit 8c1dd97a8c
Signed by: bsturmfels
GPG key ID: 023C05E2C9C068F0
3 changed files with 7 additions and 7 deletions

View file

@ -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: 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: 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 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 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: 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: 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 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. version number is based on the Git revision.

View file

@ -1,6 +1,5 @@
# To-do # To-do
* Avoid hard-coding the bank account * 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 employee-name->entity-tag into config
* Potentially move cat->payroll-type into config * Potentially move cat->payroll-type into config

View file

@ -11,7 +11,8 @@
(:gen-class)) (:gen-class))
(def cli-options (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)" [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"] :validate [#(re-matches #"\d{4}-\d{2}-\d{2}" %) "Must be of format YYYY-MM-DD"]
:default "TODO-DATE"] :default "TODO-DATE"]
@ -60,7 +61,7 @@
(System/exit 0)) (System/exit 0))
(when errors (when errors
(println (println
(str "The following errors occurred while parsing your command:\n\n" (str "The following errors occurred:\n\n"
(str/join \newline errors))) (str/join \newline errors)))
(System/exit 1)) (System/exit 1))
(let [{:keys [date period pay-receipt-no pay-invoice-no total-fees project]} options (let [{:keys [date period pay-receipt-no pay-invoice-no total-fees project]} options