|
36 | 36 | :help "Output version information."} |
37 | 37 | :default {:kind :option}]) |
38 | 38 |
|
39 | | -(defn- run-with-file-path [arguments file-path] |
| 39 | +(defn run-with-file-path [arguments file-path] |
40 | 40 | (def load-file-result (file_repository/load file-path)) |
41 | | - (def errors (load-file-result :errors)) |
42 | | - (if errors |
43 | | - (errors/print-errors errors (errors/exit-status-codes :file-error)) |
| 41 | + (def file-errors (load-file-result :errors)) |
| 42 | + (if (any? file-errors) |
| 43 | + [file-errors (errors/exit-status-codes :file-error)] |
44 | 44 | (let [plan-string (load-file-result :text) |
45 | 45 | parse-result (plan_parser/parse plan-string) |
46 | 46 | parse-errors (parse-result :errors) |
47 | 47 | plan (parse-result :plan)] |
48 | | - (if (empty? parse-errors) |
| 48 | + (if (any? parse-errors) |
| 49 | + [parse-errors (errors/exit-status-codes :parse-error)] |
49 | 50 | (let [{:plan new-plan :errors run-errors} (run-commands plan file-path arguments)] |
50 | | - (if (empty? run-errors) |
| 51 | + (if (any? run-errors) |
| 52 | + [run-errors (errors/exit-status-codes :command-error)] |
51 | 53 | (let [serialize-empty-inbox (plan_parser/serialize-empty-inbox? plan-string) |
52 | 54 | new-plan-string (plan_serializer/serialize |
53 | 55 | new-plan |
54 | 56 | {:serialize-empty-inbox serialize-empty-inbox})] |
55 | | - (file_repository/save new-plan-string file-path)) |
56 | | - (errors/print-errors run-errors (errors/exit-status-codes :command-error))) |
57 | | - (errors/print-errors parse-errors (errors/exit-status-codes :parse-error))))))) |
| 57 | + (file_repository/save new-plan-string file-path) |
| 58 | + errors/no-error))))))) |
58 | 59 |
|
59 | | -(defn- run-with-arguments [arguments] |
| 60 | +(defn run-with-arguments [arguments] |
60 | 61 | (def file-path (arguments :default)) |
61 | 62 | (if file-path |
62 | 63 | (run-with-file-path arguments file-path) |
63 | 64 | (if (arguments "version") |
64 | | - (print-version) |
65 | | - (errors/print-errors ["Plan file path is missing"] |
66 | | - (errors/exit-status-codes :plan-path-missing))))) |
| 65 | + (do |
| 66 | + (print-version) |
| 67 | + errors/no-error) |
| 68 | + [["Plan file path is missing"] |
| 69 | + (errors/exit-status-codes :plan-path-missing)]))) |
67 | 70 |
|
68 | 71 | ## ————————————————————————————————————————————————————————————————————————————————————————————————— |
69 | 72 | ## Public Interface |
70 | 73 |
|
71 | 74 | (defn main [& args] |
72 | 75 | (def arguments (argparse ;argparse-params)) |
73 | 76 | (if arguments |
74 | | - (run-with-arguments arguments))) |
| 77 | + (let [[errors exit-code] (run-with-arguments arguments)] |
| 78 | + (errors/print-errors errors (errors/exit-status-codes exit-code))))) |
0 commit comments