Refactor bin/doom
So innocuous CLI command return values don't break the post-script written to /tmp/doom.sh.
This commit is contained in:
parent
b237de5619
commit
1e9870e13a
3 changed files with 138 additions and 111 deletions
|
@ -127,23 +127,25 @@ Environment variables:
|
|||
(when command
|
||||
(push command args))
|
||||
(setq command "help"))
|
||||
(if (null command)
|
||||
(doom-cli-execute "help")
|
||||
(let ((start-time (current-time)))
|
||||
(run-hooks 'doom-cli-pre-hook)
|
||||
(when (apply #'doom-cli-execute command args)
|
||||
(run-hooks 'doom-cli-post-hook)
|
||||
(print! (success "Finished in %s")
|
||||
(let* ((duration (float-time (time-subtract (current-time) before-init-time)))
|
||||
(hours (/ (truncate duration) 60 60))
|
||||
(minutes (- (/ (truncate duration) 60) (* hours 60)))
|
||||
(seconds (- duration (* hours 60 60) (* minutes 60))))
|
||||
(string-join
|
||||
(delq
|
||||
nil (list (unless (zerop hours) (format "%dh" hours))
|
||||
(unless (zerop minutes) (format "%dm" minutes))
|
||||
(format (if (> duration 60) "%ds" "%.4fs")
|
||||
seconds)))))))))))
|
||||
(cons
|
||||
t (if (null command)
|
||||
(doom-cli-execute "help")
|
||||
(let ((start-time (current-time)))
|
||||
(run-hooks 'doom-cli-pre-hook)
|
||||
(when-let (result (apply #'doom-cli-execute command args))
|
||||
(run-hooks 'doom-cli-post-hook)
|
||||
(print! (success "Finished in %s")
|
||||
(let* ((duration (float-time (time-subtract (current-time) before-init-time)))
|
||||
(hours (/ (truncate duration) 60 60))
|
||||
(minutes (- (/ (truncate duration) 60) (* hours 60)))
|
||||
(seconds (- duration (* hours 60 60) (* minutes 60))))
|
||||
(string-join
|
||||
(delq
|
||||
nil (list (unless (zerop hours) (format "%dh" hours))
|
||||
(unless (zerop minutes) (format "%dm" minutes))
|
||||
(format (if (> duration 60) "%ds" "%.4fs")
|
||||
seconds))))))
|
||||
result))))))
|
||||
;; TODO Not implemented yet
|
||||
(doom-cli-command-not-found-error
|
||||
(print! (error "Command 'doom %s' not recognized") (string-join (cdr e) " "))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue