Rewrite interactive CLI commands
- Replace doom//upgrade with doom/upgrade - Replace doom//autoloads with doom/reload-autoloads - Replace doom//refresh with doom/reload - Remove doom//install; there should be no workflow for this command - Remove doom//autoremove; autoremove was replaced with purge. Maybe I'll write a doom//purge analogue. Not sure yet. - Use compile instead of hacky wrapper around core-cli API Rewrite interactive CLI commands - Rewrite doom//upgrade & doom//autoloads - Remove doom//install; there really should be no use-case for it - Remove doom//autoremove; autoremove was replaced with purge. I'll get around to writing a doom//purge eventually. fixup! Rewrite interactive CLI commands
This commit is contained in:
parent
0f9e60d62c
commit
1e6ef4d6e4
3 changed files with 57 additions and 111 deletions
6
bin/doom
6
bin/doom
|
@ -75,7 +75,8 @@ with a different private module."
|
|||
start-time)))))
|
||||
(user-error
|
||||
(print! (error "%s\n") (error-message-string e))
|
||||
(print! (yellow "See 'doom help %s' for documentation on this command.") (car args)))
|
||||
(print! (yellow "See 'doom help %s' for documentation on this command.") (car args))
|
||||
(error "")) ; Ensure non-zero exit code
|
||||
((debug error)
|
||||
(print! (error "There was an unexpected error:"))
|
||||
(print-group!
|
||||
|
@ -99,8 +100,7 @@ with a different private module."
|
|||
(string-join (append (list (file-name-nondirectory load-file-name) "-d" command)
|
||||
args)
|
||||
" "))
|
||||
;; Ensure the process returns non-zero
|
||||
(error "")))))))
|
||||
(error ""))))))) ; Ensure non-zero exit code
|
||||
|
||||
(doom-cli-execute :main (cdr (member "--" argv)))
|
||||
(setq argv nil))
|
||||
|
|
|
@ -1,86 +1,5 @@
|
|||
;;; core/autoload/cli.el -*- lexical-binding: t; -*-
|
||||
|
||||
;; Externs
|
||||
(defvar evil-collection-mode-list)
|
||||
|
||||
;;;###autoload
|
||||
(defun doom--cli-run (command &rest _args)
|
||||
(require 'core-cli)
|
||||
(require 'core-packages)
|
||||
(require 'straight)
|
||||
(when (featurep 'general)
|
||||
(general-auto-unbind-keys))
|
||||
(let* ((evil-collection-mode-list nil)
|
||||
(default-directory doom-emacs-dir)
|
||||
(buf (get-buffer-create " *bin/doom*"))
|
||||
(doom-format-backend 'ansi)
|
||||
(ignore-window-parameters t)
|
||||
(noninteractive t)
|
||||
(standard-output
|
||||
(lambda (char)
|
||||
(with-current-buffer buf
|
||||
(insert char)
|
||||
(when (memq char '(?\n ?\r))
|
||||
(ansi-color-apply-on-region (line-beginning-position -1) (line-end-position))
|
||||
(redisplay))))))
|
||||
(setq doom-modules (doom-modules))
|
||||
(with-current-buffer (switch-to-buffer buf)
|
||||
(erase-buffer)
|
||||
(require 'package)
|
||||
(redisplay)
|
||||
(doom-cli-execute command nil)
|
||||
(print! (green "\nDone!"))))
|
||||
(when (featurep 'general)
|
||||
(general-auto-unbind-keys 'undo))
|
||||
(message (format! (green "Done!"))))
|
||||
|
||||
|
||||
;;;###autoload
|
||||
(defun doom//autoloads (&optional yes)
|
||||
"TODO"
|
||||
(interactive "P")
|
||||
(let ((doom-auto-accept yes))
|
||||
(doom--cli-run "autoloads")))
|
||||
|
||||
;;;###autoload
|
||||
(defun doom//update (&optional yes)
|
||||
"TODO"
|
||||
(interactive "P")
|
||||
(let ((doom-auto-accept yes))
|
||||
(doom--cli-run "update")))
|
||||
|
||||
;;;###autoload
|
||||
(defun doom//upgrade (&optional yes)
|
||||
"TODO"
|
||||
(interactive "P")
|
||||
(let ((doom-auto-accept yes))
|
||||
(doom--cli-run "upgrade"))
|
||||
(when (y-or-n-p "You must restart Emacs for the upgrade to take effect. Restart?")
|
||||
(doom/restart-and-restore)))
|
||||
|
||||
;;;###autoload
|
||||
(defun doom//install (&optional yes)
|
||||
"TODO"
|
||||
(interactive "P")
|
||||
(let ((doom-auto-accept yes))
|
||||
(doom--cli-run "install")))
|
||||
|
||||
;;;###autoload
|
||||
(defun doom//autoremove (&optional yes)
|
||||
"TODO"
|
||||
(interactive "P")
|
||||
(let ((doom-auto-accept yes))
|
||||
(doom--cli-run "autoremove")))
|
||||
|
||||
;;;###autoload
|
||||
(defun doom//refresh (&optional yes)
|
||||
"TODO"
|
||||
(interactive "P")
|
||||
(let ((doom-auto-accept yes))
|
||||
(doom--cli-run "refresh")))
|
||||
|
||||
|
||||
|
||||
;;
|
||||
;;; Library
|
||||
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
;;; core/autoload/config.el -*- lexical-binding: t; -*-
|
||||
|
||||
(defvar doom-bin-dir (concat doom-emacs-dir "bin/"))
|
||||
(defvar doom-bin (concat doom-bin-dir "doom"))
|
||||
|
||||
;;;###autoload
|
||||
(defvar doom-reload-hook nil
|
||||
"A list of hooks to run when `doom/reload' is called.")
|
||||
|
@ -45,6 +48,21 @@
|
|||
(interactive)
|
||||
(find-file (expand-file-name "packages.el" doom-private-dir)))
|
||||
|
||||
|
||||
;;
|
||||
;;; Managements
|
||||
|
||||
(cl-defmacro doom--compile (command &key on-success on-failure)
|
||||
(declare (indent defun))
|
||||
`(with-current-buffer (compile ,command)
|
||||
(add-hook
|
||||
'compilation-finish-functions
|
||||
(lambda (_buf status)
|
||||
(if (equal status "finished\n")
|
||||
,on-success
|
||||
,on-failure))
|
||||
nil 'local)))
|
||||
|
||||
;;;###autoload
|
||||
(defun doom/reload ()
|
||||
"Reloads your private config.
|
||||
|
@ -55,25 +73,20 @@ reloads your package list, and lastly, reloads your private config.el.
|
|||
|
||||
Runs `doom-reload-hook' afterwards."
|
||||
(interactive)
|
||||
(or (y-or-n-p
|
||||
(concat "You are about to reload your Doom config from within Emacs. This "
|
||||
"is highly experimental and may cause issues. It is recommended you "
|
||||
"use 'bin/doom refresh' on the command line instead.\n\n"
|
||||
"Reload anyway?"))
|
||||
(user-error "Aborted"))
|
||||
(require 'core-cli)
|
||||
(doom--compile (format "%s refresh" doom-bin)
|
||||
:on-success
|
||||
(let ((doom-reloading-p t))
|
||||
(compile (format "%s/bin/doom refresh" doom-emacs-dir))
|
||||
(while compilation-in-progress
|
||||
(sit-for 1))
|
||||
(doom-initialize 'force)
|
||||
(with-demoted-errors "PRIVATE CONFIG ERROR: %s"
|
||||
(general-auto-unbind-keys)
|
||||
(unwind-protect
|
||||
(doom-initialize-modules 'force)
|
||||
(general-auto-unbind-keys t)))
|
||||
(run-hook-wrapped 'doom-reload-hook #'doom-try-run-hook))
|
||||
(message "Finished!"))
|
||||
(run-hook-wrapped 'doom-reload-hook #'doom-try-run-hook)
|
||||
(print! (success "Config successfully reloaded!")))
|
||||
:on-failure
|
||||
(user-error "Failed to reload your config")))
|
||||
|
||||
;;;###autoload
|
||||
(defun doom/reload-autoloads ()
|
||||
|
@ -92,14 +105,28 @@ line."
|
|||
(doom-cli-reload-autoloads nil 'force))
|
||||
|
||||
;;;###autoload
|
||||
(defun doom/reload-env ()
|
||||
"Regenerates and reloads your shell environment.
|
||||
(defun doom/reload-env (&optional arg)
|
||||
"Regenerates and/or reloads your envvar file.
|
||||
|
||||
Uses the same mechanism as 'bin/doom env reload'."
|
||||
If passed the prefix ARG, clear the envvar file. Uses the same mechanism as
|
||||
'bin/doom env'.
|
||||
|
||||
An envvar file contains a snapshot of your shell environment, which can be
|
||||
imported into Emacs."
|
||||
(interactive "P")
|
||||
(doom--compile (format "%s env%s" doom-bin (if arg " -c" ""))
|
||||
:on-success
|
||||
(let ((doom-reloading-p t))
|
||||
(unless arg
|
||||
(doom-load-envvars-file doom-env-file)))
|
||||
:on-failure
|
||||
(error "Failed to generate env file")))
|
||||
|
||||
;;;###autoload
|
||||
(defun doom/upgrade ()
|
||||
"Run 'doom upgrade' then prompt to restart Emacs."
|
||||
(interactive)
|
||||
(compile (format "%s env" (expand-file-name "bin/doom" doom-emacs-dir)))
|
||||
(while compilation-in-progress
|
||||
(sit-for 1))
|
||||
(unless (file-readable-p doom-env-file)
|
||||
(error "Failed to generate env file"))
|
||||
(doom-load-envvars-file doom-env-file))
|
||||
(doom--compile (format "%s upgrade" doom-bin)
|
||||
:on-success
|
||||
(when (y-or-n-p "You must restart Emacs for the upgrade to take effect.\n\nRestart Emacs?")
|
||||
(doom/restart-and-restore))))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue