                         "id" (get arguments 1)
                         "due-date" (unparse-date (t/plus (parse-date (:issue-date options))
                                                          (t/days (:net options)))))))
-
-(defn cwd []
-  (System/getProperty "user.dir"))
-
-(defn get-invoice-filenames []
-  (filter #(.endsWith % ".json") (map #(.getName %) (file-seq (io/file (cwd))))))
-
-(defn read-all-invoices []
-  (map read-json (get-invoice-filenames)))
-
-(defn options-to-filter [options]
-  (fn [invoice]
-    (every? #(= (get options %) (get invoice (name %))) (keys options))))
-
-(defn pretty-print-invoice [invoice]
-  (format (->> ["\nInvoice #%s"
-                "Client: %s"
-                "Issue date: %s"
-                "Due date: %s (Net %d)"
-                "Amount: %d %s"]
-               (string/join \newline))
-          (get invoice "id")
-          (get invoice "client")
-          (get invoice "issue-date")
-          (get invoice "due-date")
-          (get invoice "net")
-          (get invoice "amount")
-          (get invoice "currency")))
 
 (defn data [options]
   (println (json/write-str (filter (options-to-filter options) (read-all-invoices)))))

  (println msg)
  (System/exit status))

(defn read-json [file]
  (json/read-str (slurp file)))

(defn write-json [file value]
  (with-open [w (io/writer file)]
    (.write w (json/write-str value))))

(defn id-to-filename [id]
  (str id ".json"))

(defn read-invoice [id]
  (read-json (id-to-filename id)))

(defn write-invoice [id value]
  (write-json (id-to-filename id) value))

(defn create [options arguments]
  (cond
    (not (:currency options)) (exit 1 (error-msg ["-c CURRENCY is required"]))

(defn parse-date [date-string]
  (f/parse date-formatter date-string))

(defn read-json [file]
  (json/read-str (slurp file)))

(defn write-json [file value]
  (with-open [w (io/writer file)]
    (.write w (json/write-str value))))

(defn id-to-filename [id]
  (str id ".json"))

(defn read-invoice [id]
  (read-json (id-to-filename id)))

(defn write-invoice [id value]
  (write-json (id-to-filename id) value))

(defn get-invoice-filenames []
  (filter #(.endsWith % ".json") (map #(.getName %) (file-seq (io/file (cwd))))))

(defn read-all-invoices []
  (map read-json (get-invoice-filenames)))

(defn pretty-print-invoice [invoice]
  (format (->> ["\nInvoice #%s"
                "Client: %s"
                "Issue date: %s"
                "Due date: %s (Net %d)"
                "Amount: %d %s"]
               (string/join \newline))
          (get invoice "id")
          (get invoice "client")
          (get invoice "issue-date")
          (get invoice "due-date")
          (get invoice "net")
          (get invoice "amount")
          (get invoice "currency")))

(defn options-to-filter [options]
  (fn [invoice]
    (every? #(= (println %) (get options %) (get invoice (name %))) (keys options))))

(def cli-options
  ;; TODO: add clever currency default
  [["-c" "--currency CURRENCY" "Invoice currency"]
   ["-r" "--client CLIENT" "Client"]
   ["-f" "--filename FILENAME" "Attached file"]
   ["-i" "--issue-date ISSUE_DATE" "Issue date"]
   ["-p" "--paid-on PAID_ON" "Paid on"]
   ["-n" "--net NET" "Net"
    :parse-fn #(Integer/parseInt %)]
   ["-a" "--amount AMOUNT" "Total amount"
    :parse-fn #(Integer/parseInt %)]])

(defn parse-today-default [value]
  (cond
    (nil? value) (unparse-date (t/now))
    (string? value) value))

(defn usage [options-summary]
  (->> ["invadm - an invoice manager"
