Skip to content

Commit

Permalink
Move task printing to a separate function
Browse files Browse the repository at this point in the history
  • Loading branch information
chaitanyagupta committed Nov 18, 2018
1 parent df7365e commit 6739331
Showing 1 changed file with 38 additions and 26 deletions.
64 changes: 38 additions & 26 deletions deftask-cli.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,38 @@
:arg-parser #'identity
:meta-var "DETAIL"))

(defun print-task (task &key detailed project-labels project-members)
(termcolor:with-color (:style :bright)
(format t "#~D" (assocrv :task-id task)))
(format t "~:[~;~] ~A~%" (string= (assocrv :state task) "open") (assocrv :title task))
(when detailed
(flet ((show-time (time-string field-name)
(let ((time (local-time:parse-timestring time-string)))
(format t "~A ~A" field-name (relative-time time)))))
(termcolor:with-color (:style :dim)
(write-string " ")
(show-time (assocrv :created-at task) "Created")
(write-string ", ")
(show-time (assocrv :updated-at task) "last updated")
(terpri)))
(when-let (label-ids (assocrv :label-ids task))
(setf project-labels (or project-labels (deftask:get-labels)))
(let* ((task-labels (mapcar (lambda (label-id)
(find label-id project-labels :key (assocrv-fn :label-id)))
label-ids))
(task-label-names (mapcar (assocrv-fn :name) task-labels)))
(termcolor:with-color (:style :dim)
(format t " Labels: ~{~A~^, ~}~%" task-label-names))))
(when-let (assignee-ids (assocrv :assignee-ids task))
(setf project-members (or project-members
(deftask:get-project-members deftask:*project-id*)))
(let* ((assignees (mapcar (lambda (assignee-id)
(find assignee-id project-members :key (assocrv-fn '(:user :user-id))))
assignee-ids))
(assignee-names (mapcar (assocrv-fn '(:user :name)) assignees)))
(termcolor:with-color (:style :dim)
(format t " Assignees: ~{~A~^, ~}~%" assignee-names))))))

(defun subcommand-ls (argv)
(with-options-and-free-args (*ls-opts* argv)
(with-token-and-project-id
Expand Down Expand Up @@ -315,32 +347,12 @@
(format t "Ordered by ~A~%" order-by)
(format t "---~%")
(dolist (task tasks)
(termcolor:with-color (:style :bright)
(format t "#~D" (assocrv :task-id task)))
(format t "~:[~;~] ~A~%" (string= (assocrv :state task) "open") (assocrv :title task))
(when (or (null detail) (string= detail "detailed"))
(let* ((time-string (if (starts-with-subseq "updated-at" order-by)
(assocrv :updated-at task)
(assocrv :created-at task)))
(time (local-time:parse-timestring time-string)))
(termcolor:with-color (:style :dim)
(format t " ~A: ~A~%"
(if (starts-with-subseq "updated-at" order-by) "Updated" "Created")
(relative-time time :sentencep nil))))
(when-let (label-ids (assocrv :label-ids task))
(let* ((task-labels (mapcar (lambda (label-id)
(find label-id labels :key (assocrv-fn :label-id)))
label-ids))
(task-label-names (mapcar (assocrv-fn :name) task-labels)))
(termcolor:with-color (:style :dim)
(format t " Labels: ~{~A~^, ~}~%" task-label-names))))
(when-let (assignee-ids (assocrv :assignee-ids task))
(let* ((assignees (mapcar (lambda (assignee-id)
(find assignee-id members :key (assocrv-fn '(:user :user-id))))
assignee-ids))
(assignee-names (mapcar (assocrv-fn '(:user :name)) assignees)))
(termcolor:with-color (:style :dim)
(format t " Assignees: ~{~A~^, ~}~%" assignee-names))))))))))
(if (or (null detail) (string= detail "detailed"))
(print-task task
:detailed t
:project-labels labels
:project-members members)
(print-task task)))))))

(defun subcommand-close (argv)
(with-options-and-free-args (*main-opts* argv)
Expand Down

0 comments on commit 6739331

Please sign in to comment.