core-cli: backport more refactors from rewrite
Still a long way to go, but this introduces a few niceties for debugging CLI failures: + The (extended) output of the last bin/doom command is now logged to ~/.emacs.d/.local/doom.log + If an error occurs, short backtraces are displayed whether or not you have debug mode on. The full backtrace is written to ~/.emacs.d/.local/doom.error.log. + bin/doom now aborts with a warning if: - The script itself or its parent directory is a symlink. It's fine if ~/.emacs.d is symlinked though. - Running bin/doom as root when your DOOMDIR isn't in /root/. - If you're sporting Emacs 26.1 (now handled in the elisp side rather than the /bin/sh shebang preamble). + If a 'doom sync' was aborted prematurely, you'll be warned that Doom was left in an inconsistent state and that you must run `doom sync` again. May address #3746
This commit is contained in:
parent
7e362e8fbd
commit
e632871a11
11 changed files with 393 additions and 242 deletions
|
@ -14,7 +14,7 @@ one wants that.")
|
|||
auto-mode-alist
|
||||
interpreter-mode-alist
|
||||
Info-directory-list)
|
||||
"A list of variables to be cached in `doom-autoload-file'.")
|
||||
"A list of variables to be cached in `doom-autoloads-file'.")
|
||||
|
||||
(defvar doom-autoloads-files ()
|
||||
"A list of additional files or file globs to scan for autoloads.")
|
||||
|
@ -26,7 +26,7 @@ one wants that.")
|
|||
(defun doom-autoloads-reload (&optional file)
|
||||
"Regenerates Doom's autoloads and writes them to FILE."
|
||||
(unless file
|
||||
(setq file doom-autoload-file))
|
||||
(setq file doom-autoloads-file))
|
||||
(print! (start "(Re)generating autoloads file..."))
|
||||
(print-group!
|
||||
(cl-check-type file string)
|
||||
|
|
56
core/cli/sync.el
Normal file
56
core/cli/sync.el
Normal file
|
@ -0,0 +1,56 @@
|
|||
;;; core/cli/sync.el -*- lexical-binding: t; -*-
|
||||
|
||||
(defcli! (sync s)
|
||||
((no-envvar-p ["-e"] "Don't regenerate the envvar file")
|
||||
(no-elc-p ["-c"] "Don't recompile config")
|
||||
(update-p ["-u"] "Update installed packages after syncing")
|
||||
(purge-p ["-p" "--prune"] "Purge orphaned package repos & regraft them"))
|
||||
"Synchronize your config with Doom Emacs.
|
||||
|
||||
This is the equivalent of running autoremove, install, autoloads, then
|
||||
recompile. Run this whenever you:
|
||||
|
||||
1. Modify your `doom!' block,
|
||||
2. Add or remove `package!' blocks to your config,
|
||||
3. Add or remove autoloaded functions in module autoloaded files.
|
||||
4. Update Doom outside of Doom (e.g. with git)
|
||||
|
||||
It will ensure that unneeded packages are removed, all needed packages are
|
||||
installed, autoloads files are up-to-date and no byte-compiled files have gone
|
||||
stale."
|
||||
(add-hook 'kill-emacs-hook #'doom--cli-abort-warning-h)
|
||||
(print! (start "Synchronizing your config with Doom Emacs..."))
|
||||
(unwind-protect
|
||||
(print-group!
|
||||
(delete-file doom-autoloads-file)
|
||||
(when (and (not no-envvar-p)
|
||||
(file-exists-p doom-env-file))
|
||||
(doom-cli-reload-env-file 'force))
|
||||
(run-hooks 'doom-sync-pre-hook)
|
||||
(doom-cli-packages-install)
|
||||
(doom-cli-packages-build)
|
||||
(when update-p
|
||||
(doom-cli-packages-update))
|
||||
(doom-cli-packages-purge purge-p 'builds-p purge-p purge-p)
|
||||
(run-hooks 'doom-sync-post-hook)
|
||||
(when (doom-autoloads-reload)
|
||||
(print! (info "Restart Emacs or use 'M-x doom/reload' for changes to take effect")))
|
||||
t)
|
||||
(remove-hook 'kill-emacs-hook #'doom--cli-abort-warning-h)))
|
||||
|
||||
|
||||
;;
|
||||
;;; DEPRECATED Commands
|
||||
|
||||
(defcli! (refresh re) ()
|
||||
"Deprecated for 'doom sync'"
|
||||
:hidden t
|
||||
(user-error "'doom refresh' has been replaced with 'doom sync'. Use that instead"))
|
||||
|
||||
|
||||
;;
|
||||
;;; Helpers
|
||||
|
||||
(defun doom--cli-abort-warning-h ()
|
||||
(terpri)
|
||||
(print! (warn "Script was abruptly aborted! Run 'doom sync' to repair inconsistencies")))
|
|
@ -24,7 +24,7 @@ following shell commands:
|
|||
;; Reload Doom's CLI & libraries, in case there were any upstream changes.
|
||||
;; Major changes will still break, however
|
||||
(print! (info "Reloading Doom Emacs"))
|
||||
(doom-cli-execute-after "doom" "upgrade" "-p" (if force-p "-f")))
|
||||
(throw 'exit (list "doom" "upgrade" "-p" (if force-p "-f"))))
|
||||
|
||||
((print! "Doom is up-to-date!")))))
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue