Implement daisy-chaining for CLI sessions

elisp lacks an execv implementation (or mature subprocess library), so
we exploit some splenderiffic hackery to get Emacs to execute arbitrary
shell commands after a 'doom ...' command completes. This allows us to
daisy chain doom commands in distinct sessions (wonderful for reloading
doom after a 'doom upgrade', which we do). This minimizes errors when a
'doom upgrade' pulls in breaking changes to Doom's CLI.

We also bring 'doom run' into elisp, since this new functionality
enables us to.
This commit is contained in:
Henrik Lissner 2020-05-26 02:27:58 -04:00
parent e89b604f5f
commit a814239ec7
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
3 changed files with 45 additions and 38 deletions

View file

@ -15,16 +15,19 @@ following shell commands:
bin/doom update"
:bare t
(let ((doom-auto-discard force-p))
(if (delq
nil (list
(unless packages-only-p
(doom-cli-upgrade doom-auto-accept doom-auto-discard))
(doom-cli-execute "sync")
(when (doom-cli-packages-update)
(doom-autoloads-reload)
t)))
(print! (success "Done! Restart Emacs for changes to take effect."))
(print! "Nothing to do. Doom is up-to-date!"))))
(cond
(packages-only-p
(doom-cli-execute "sync" "-u")
(print! (success "Finished upgrading Doom Emacs")))
((not (doom-cli-upgrade doom-auto-accept doom-auto-discard))
(print! "Nothing to do. Doom is up-to-date!"))
(t
;; 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"))))))
;;
@ -113,24 +116,6 @@ following shell commands:
(equal (vc-git--rev-parse "HEAD") new-rev))
(error "Failed to check out %s" (substring new-rev 0 10)))
(print! (info "%s") (cdr result))
;; Reload Doom's CLI & libraries, in case there were any
;; upstream changes. Major changes will still break, however
(condition-case-unless-debug e
(progn
(mapc (lambda (f) (load (symbol-name f)))
'(core core-lib
core-cli
core-modules
core-packages))
(doom-initialize 'force))
(error
(signal 'doom-error
(list "Could not reload new version of Doom"
"Try running 'doom upgrade' again"
e))))
(print! (success "Finished upgrading Doom Emacs")))
t)))))
t))))))
(ignore-errors
(doom-call-process "git" "remote" "remove" doom-repo-remote))))))