Skip to content

Commit a03fc48

Browse files
committed
Extract exit status codes to errors module
1 parent e5abbcb commit a03fc48

2 files changed

Lines changed: 15 additions & 9 deletions

File tree

src/alas.janet

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
(import ./commands :prefix "")
77

8+
(import ./errors)
89
(import ./file_repository)
910
(import ./plan/parser :as plan_parser)
1011
(import ./plan/serializer :as plan_serializer)
@@ -13,12 +14,6 @@
1314
(each error errors (print (string error ".")))
1415
(os/exit exit-status-code))
1516

16-
(def exit-status-codes
17-
{:error 1
18-
:plan-path-missing 2
19-
:file-error 3
20-
:parse-error 4})
21-
2217
# Keep commands sorted alphabetically.
2318
(def argparse-params
2419
["A command line utility for planning your days"
@@ -49,13 +44,13 @@
4944
(def load-file-result (file_repository/load file-path))
5045
(def errors (load-file-result :errors))
5146
(if errors
52-
(print-errors errors (exit-status-codes :file-error))
47+
(print-errors errors (errors/exit-status-codes :file-error))
5348
(let [plan-string (load-file-result :text)
5449
parse-result (plan_parser/parse plan-string)
5550
parse-errors (parse-result :errors)
5651
plan (parse-result :plan)]
5752
(if parse-errors
58-
(print-errors parse-errors (exit-status-codes :parse-error))
53+
(print-errors parse-errors (errors/exit-status-codes :parse-error))
5954
(let [serialize-empty-inbox (plan_parser/serialize-empty-inbox? plan-string)
6055
new-plan (run-commands plan file-path arguments)
6156
new-plan-string (plan_serializer/serialize
@@ -71,7 +66,7 @@
7166
(print-version)
7267
(do
7368
(print "Plan file path missing.")
74-
(os/exit (exit-status-codes :plan-path-missing))))))
69+
(os/exit (errors/exit-status-codes :plan-path-missing))))))
7570

7671
## —————————————————————————————————————————————————————————————————————————————————————————————————
7772
## Public Interface

src/errors.janet

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
### ————————————————————————————————————————————————————————————————————————————————————————————————
2+
### Errors.
3+
4+
## —————————————————————————————————————————————————————————————————————————————————————————————————
5+
## Public Interface
6+
7+
(def exit-status-codes
8+
{:error 1
9+
:plan-path-missing 2
10+
:file-error 3
11+
:parse-error 4})

0 commit comments

Comments
 (0)