File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11# ## ————————————————————————————————————————————————————————————————————————————————————————————————
22# ## This module implements the list contacts command.
33
4+ (import ../utils :prefix " " )
45(import ../date :as d )
56(import ../contact/repository :as contacts_repository )
67
3233 (def argument (arguments " list-contacts" ))
3334 (if argument
3435 (let [load-result (contacts_repository/load-contacts argument )
35- error (load-result :error )]
36- (if error
37- {:errors [( string " --list-contacts " ( string/ascii-lower error ))] }
36+ errors (load-result :errors )]
37+ (if errors
38+ {:errors ( format-command-errors " --list-contacts" errors ) }
3839 {:command [print-contacts (load-result :contacts )]}))
3940 {}))
Original file line number Diff line number Diff line change 11# ## ————————————————————————————————————————————————————————————————————————————————————————————————
22# ## This module implements a command for scheduling contacts for today in a plan.
33
4+ (import ../utils :prefix " " )
5+
46(import ../contact )
57(import ../date )
68(import ../day )
6466 (def argument (arguments " schedule-contacts" ))
6567 (if argument
6668 (let [load-result (contacts_repository/load-contacts argument )
67- error (load-result :error )
69+ errors (load-result :errors )
6870 contacts (load-result :contacts )]
69- (if error
70- {:errors [( string " --schedule-contacts " ( string/ascii-lower error ))] }
71+ (if errors
72+ {:errors ( format-command-errors " --schedule-contacts" errors ) }
7173 {:command [schedule-contacts contacts (date/today )]}))
7274 {}))
Original file line number Diff line number Diff line change 11# ## ————————————————————————————————————————————————————————————————————————————————————————————————
22# ## This module implements a command for scheduling days for today in a plan.
33
4+ (import ../utils :prefix " " )
5+
46(import ../date )
57(import ../day )
68(import ../plan )
4951 (task/mark-as-missed task (day :date ))))
5052 tasks ))
5153
52- (defn- format-errors [errors ]
53- (map (fn [error ] (string command " " (string/ascii-lower error ) " ." )) errors ))
54-
5554# # —————————————————————————————————————————————————————————————————————————————————————————————————
5655# # Public Interface
5756
7473 (let [load-file-result (file_repository/load argument )
7574 errors (load-file-result :errors )]
7675 (if errors
77- {:errors (format-errors errors )}
76+ {:errors (format-command- errors command errors )}
7877 (let [parse-result (schedule_parser/parse (load-file-result :text ))
7978 errors (parse-result :errors )]
8079 (if errors
81- {:errors (format-errors errors )}
80+ {:errors (format-command- errors command errors )}
8281 {:command [schedule-tasks (parse-result :tasks ) (date/today )]}))))
8382 {}))
Original file line number Diff line number Diff line change 11# ## ————————————————————————————————————————————————————————————————————————————
22# ## This module implements stats command.
33
4- (import ../utils :as " u " )
4+ (import ../utils :prefix " " )
55(import ../plan )
66
77# # —————————————————————————————————————————————————————————————————————————————
1212 Prints stats for the plan. Returns the plan.
1313 ```
1414 [plan ]
15- (print (u/ pluralize (length (plan :days )) " day" ))
16- (print (u/ pluralize (length (plan/completed-tasks plan )) " completed task" ))
17- (print (u/ pluralize (length (plan/pending-tasks plan )) " pending task" ))
15+ (print (pluralize (length (plan :days )) " day" ))
16+ (print (pluralize (length (plan/completed-tasks plan )) " completed task" ))
17+ (print (pluralize (length (plan/pending-tasks plan )) " pending task" ))
1818 plan )
1919
2020(defn build-command [arguments & ]
Original file line number Diff line number Diff line change 11# ## ————————————————————————————————————————————————————————————————————————————————————————————————
22# ## This module implements a repository that loads contacts from Markdown files.
33
4- (import ../file_repository )
54(import ../utils )
5+
6+ (import ../file_repository )
67(import ./parser :as contact_parser )
78
89(defn- load-contact [contact-path ]
2223 (fn [contact-file ] (load-contact (string directory " /" contact-file )))
2324 (os/dir directory )))]
2425 {:contacts contacts })
25- {:error " Directory does not exist. " }))
26+ {:errors [ " Directory does not exist" ] }))
Original file line number Diff line number Diff line change 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 ))
Original file line number Diff line number Diff line change 1414
1515(deftest load-contacts-when-directory-does-not-exist
1616 (def result (load-contacts " test/missing-directory" ))
17- (is (= " Directory does not exist. " (result :error ))))
17+ (is (= " Directory does not exist" (first ( result :errors ) ))))
1818
1919(run-tests! )
You can’t perform that action at this time.
0 commit comments