Skip to content

Commit cfdfc25

Browse files
committed
Move format-command-errors to errors module
1 parent 38ab13e commit cfdfc25

5 files changed

Lines changed: 10 additions & 7 deletions

File tree

src/commands/list_contacts.janet

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
(import ../utils :prefix "")
55
(import ../date :as d)
6+
(import ../errors)
67
(import ../contact/repository :as contacts_repository)
78

89
(defn- to-csv-line [contact]
@@ -35,6 +36,6 @@
3536
(let [load-result (contacts_repository/load-contacts argument)
3637
errors (load-result :errors)]
3738
(if errors
38-
{:errors (format-command-errors "--list-contacts" errors)}
39+
{:errors (errors/format-command-errors "--list-contacts" errors)}
3940
{:command [print-contacts (load-result :contacts)]}))
4041
{}))

src/commands/schedule_contacts.janet

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
### ————————————————————————————————————————————————————————————————————————————————————————————————
22
### This module implements a command for scheduling contacts for today in a plan.
33

4+
(import ../errors)
45
(import ../utils :prefix "")
56

67
(import ../contact)
@@ -69,6 +70,6 @@
6970
errors (load-result :errors)
7071
contacts (load-result :contacts)]
7172
(if errors
72-
{:errors (format-command-errors "--schedule-contacts" errors)}
73+
{:errors (errors/format-command-errors "--schedule-contacts" errors)}
7374
{:command [schedule-contacts contacts (date/today)]}))
7475
{}))

src/commands/schedule_tasks.janet

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
(import ../plan)
99
(import ../task)
1010

11+
(import ../errors)
1112
(import ../file_repository)
1213
(import ../schedule_parser)
1314

@@ -84,10 +85,10 @@
8485
(let [load-file-result (file_repository/load argument)
8586
errors (load-file-result :errors)]
8687
(if errors
87-
{:errors (format-command-errors command errors)}
88+
{:errors (errors/format-command-errors command errors)}
8889
(let [parse-result (schedule_parser/parse (load-file-result :text))
8990
errors (parse-result :errors)]
9091
(if errors
91-
{:errors (format-command-errors command errors)}
92+
{:errors (errors/format-command-errors command errors)}
9293
{:command [schedule-tasks (parse-result :tasks) (date/today)]}))))
9394
{}))

src/errors.janet

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@
1313
(defn print-errors [errors exit-status-code]
1414
(each error errors (print (string error ".")))
1515
(os/exit exit-status-code))
16+
17+
(defn format-command-errors [command errors]
18+
(map (fn [error] (string command " " (string/ascii-lower error) ".")) errors))

src/utils.janet

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,3 @@
1313
(if (string/has-suffix? "/" path)
1414
(string/trimr path "/")
1515
path))
16-
17-
(defn format-command-errors [command errors]
18-
(map (fn [error] (string command " " (string/ascii-lower error) ".")) errors))

0 commit comments

Comments
 (0)