core-cli: minor refactors

This commit is contained in:
Henrik Lissner 2020-08-26 22:31:46 -04:00
parent 518c97a2ac
commit a6dc9bf7e5
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
2 changed files with 25 additions and 27 deletions

View file

@ -44,7 +44,7 @@
"This is likely because this script (or its parent directory) is a symlink.\n"
"If you must use a symlink, you'll need to specify an EMACSDIR so Doom knows\n"
"where to find itself. e.g.\n\n "
(if (string-match "/fish$" (getenv "SHELL"))
(if (string-match-p "/fish$" (getenv "SHELL"))
"env EMACSDIR=~/.emacs.d doom"
"EMACSDIR=~/.emacs.d doom sync")
"\n\n"
@ -63,6 +63,15 @@
(load (expand-file-name "core/core.el" user-emacs-directory) nil t)
(require 'core-cli)
;; Use our own home-grown debugger to display and log errors + backtraces.
;; Control over its formatting is important, because Emacs produces
;; difficult-to-read debug information otherwise. By making its errors more
;; presentable (and storing them somewhere users can access later) we go a long
;; way toward making it easier for users to write better bug reports.
(setq debugger #'doom-cli--debugger
debug-on-error t
debug-ignored-errors nil)
;; HACK Load `cl' and site files manually to prevent polluting logs and stdout
;; with deprecation and/or file load messages.
(quiet! (if EMACS27+ (require 'cl))
@ -70,10 +79,11 @@
(kill-emacs
(pcase
;; Process the arguments passed to this script. `doom-cli-execute' should
;; return a boolean, integer (error code) or throw an 'exit event, which we
;; handle specially.
(apply #'doom-cli-execute :doom (cdr (member "--" argv)))
(catch 'exit
;; Process the arguments passed to this script. `doom-cli-execute' should
;; return a boolean, integer (error code) or throw an 'exit event, which
;; we handle specially.
(apply #'doom-cli-execute :doom (cdr (member "--" argv))))
;; Any non-zero integer is treated as an error code.
((and (pred integerp) code) code)
;; If, instead, we were given a list or string, copy these as shell script

View file

@ -6,6 +6,12 @@
(load! "autoload/output")
(require 'seq)
;; Create all our core directories to quell file errors.
(mapc (doom-rpartial #'make-directory 'parents)
(list doom-local-dir
doom-etc-dir
doom-cache-dir))
;; Ensure straight and the bare minimum is ready to go
(require 'core-modules)
(require 'core-packages)
@ -453,8 +459,10 @@ with a different private module."
(when auto-accept-p
(setenv "YES" auto-accept-p)
(print! (info "Confirmations auto-accept enabled")))
(setenv "__DOOMRESTART" "1")
(throw 'exit :restart))
(throw 'exit "__DOOMRESTART=1 $@"))
;; TODO Rotate logs out, instead of overwriting them?
(delete-file doom-cli-log-file)
(delete-file doom-cli-log-error-file)
(when help-p
(when command
(push command args))
@ -549,26 +557,6 @@ best to run Doom out of ~/.emacs.d and ~/.doom.d."
;;; Bootstrap
(doom-log "Initializing Doom CLI")
;; Use our own home-grown debugger to display and log errors + backtraces.
;; Control over its formatting is important, because Emacs produces
;; difficult-to-read debug information otherwise. By making its errors more
;; presentable (and storing them somewhere users can access them later) we go a
;; long way toward making it easier for users to write better bug reports.
(setq debugger #'doom-cli--debugger
debug-on-error t
debug-ignored-errors nil)
;; Clean slate for the next invocation
(delete-file doom-cli-log-file)
(delete-file doom-cli-log-error-file)
;; Create all our core directories to quell file errors
(mapc (doom-rpartial #'make-directory 'parents)
(list doom-local-dir
doom-etc-dir
doom-cache-dir))
(load! doom-module-init-file doom-private-dir t)
(maphash (doom-module-loader doom-cli-file) doom-modules)
(load! doom-cli-file doom-private-dir t)