|
5 | 5 |
|
6 | 6 | (import ./commands :prefix "") |
7 | 7 |
|
| 8 | +(import ./errors) |
8 | 9 | (import ./file_repository) |
9 | 10 | (import ./plan/parser :as plan_parser) |
10 | 11 | (import ./plan/serializer :as plan_serializer) |
11 | 12 |
|
12 | | -(defn- print-errors [errors] |
13 | | - (each error errors (print (string error ".")))) |
14 | | - |
15 | 13 | # Keep commands sorted alphabetically. |
16 | 14 | (def argparse-params |
17 | 15 | ["A command line utility for planning your days" |
|
42 | 40 | (def load-file-result (file_repository/load file-path)) |
43 | 41 | (def errors (load-file-result :errors)) |
44 | 42 | (if errors |
45 | | - (print-errors errors) |
| 43 | + (errors/print-errors errors (errors/exit-status-codes :file-error)) |
46 | 44 | (let [plan-string (load-file-result :text) |
47 | 45 | parse-result (plan_parser/parse plan-string) |
48 | 46 | parse-errors (parse-result :errors) |
49 | 47 | plan (parse-result :plan)] |
50 | 48 | (if parse-errors |
51 | | - (print-errors parse-errors) |
52 | | - (let [serialize-empty-inbox (plan_parser/serialize-empty-inbox? plan-string) |
53 | | - new-plan (run-commands plan file-path arguments) |
54 | | - new-plan-string (plan_serializer/serialize |
| 49 | + (errors/print-errors parse-errors (errors/exit-status-codes :parse-error)) |
| 50 | + (let [{:plan new-plan :errors run-errors} (run-commands plan file-path arguments)] |
| 51 | + (if (empty? run-errors) |
| 52 | + (let [serialize-empty-inbox (plan_parser/serialize-empty-inbox? plan-string) |
| 53 | + new-plan-string (plan_serializer/serialize |
55 | 54 | new-plan |
56 | 55 | {:serialize-empty-inbox serialize-empty-inbox})] |
57 | | - (file_repository/save new-plan-string file-path)))))) |
| 56 | + (file_repository/save new-plan-string file-path)) |
| 57 | + (errors/print-errors run-errors (errors/exit-status-codes :command-error)))))))) |
58 | 58 |
|
59 | 59 | (defn- run-with-arguments [arguments] |
60 | 60 | (def file-path (arguments :default)) |
61 | 61 | (if file-path |
62 | 62 | (run-with-file-path arguments file-path) |
63 | 63 | (if (arguments "version") |
64 | 64 | (print-version) |
65 | | - (print "Plan file path missing.")))) |
| 65 | + (errors/print-errors ["Plan file path is missing"] |
| 66 | + (errors/exit-status-codes :plan-path-missing))))) |
66 | 67 |
|
67 | 68 | ## ————————————————————————————————————————————————————————————————————————————————————————————————— |
68 | 69 | ## Public Interface |
|
0 commit comments