refactor(cli): restructure doom profile commands

- Replace 'doom profiles sync' with 'doom profile sync --all'.
- Move lisp/cli/profiles.el to lisp/cli/profile.el.
- Move obsolete alias to bin/doom.
This commit is contained in:
Henrik Lissner
2024-12-01 01:57:46 -05:00
parent 87a0d9d2e1
commit abedb71f96
4 changed files with 49 additions and 47 deletions

View File

@ -269,12 +269,13 @@ SEE ALSO:
(defcli-group! "Config Management"
:docs "Commands for maintaining your Doom Emacs configuration."
(defcli-autoload! ((sync s)))
(defcli-autoload! ((profiles profile)))
(defcli-autoload! ((profile pf)))
(defcli-autoload! ((upgrade up)))
(defcli-autoload! (env))
(defcli-autoload! (gc))
(defcli-autoload! (install))
(defcli-obsolete! (profiles sync) (profile sync "--all") "3.0.0")
(defcli-obsolete! ((build b)) (sync "--rebuild") "3.0.0")
(defcli-obsolete! ((purge p)) (gc) "3.0.0")

View File

@ -1,56 +1,38 @@
;;; lisp/cli/profiles.el -*- lexical-binding: t; -*-
;;; lisp/cli/profile.el -*- lexical-binding: t; -*-
;;; Commentary:
;;; Code:
;;
;;; Variables
(defvar doom-cli-known-profiles-file
(file-name-concat doom-cache-dir (format "profiles.%s.el" (or (car doom-profile) "@")))
;; REVIEW: Use `doom-profile-data-dir' in v3
;; (file-name-concat doom-profile-data-dir "known-profiles.el")
"TODO")
(doom-require 'doom-lib 'profiles)
;;
;;; doom profile ...
(defcli-stub! ((profile pf)) ())
(defcli! ((profile pf)) ()
"Emacs profile management commands."
:partial t)
(defcli-stub! (profile hash) ())
(defcli-stub! (profile new) ())
(defcli-stub! (profile archive) ())
(defcli-stub! (profile (remove rm)) ())
(defcli-stub! (profile (rename mv)) ())
(defcli-stub! (profile nuke) ())
;;
;;; doom profiles ...
(defcli! (profiles sync) ((reload? ("--reload")))
(defcli! (profile sync)
((all? ("--all") "Synchronize all known profiles")
(reload? ("--reload") "Forcibly reload profile load file, even if its up-to-date"))
"Synchronize your profiles with Doom."
:benchmark t
(let* ((old-profiles (doom-profiles-read doom-cli-known-profiles-file))
(new-profiles (doom-profiles-autodetect))
(load-file doom-profile-load-file)
(version (doom-file-read load-file :by 'read :noerror t))
(recreate? (or (not reload?) (doom-profiles-outdated-p))))
(unless (file-exists-p load-file)
(print! (warn "No profile loader found. Generating one..."))
(print-group! (print! (start "Regenerating it...")))
(setq recreate? t))
(unless (equal (or version doom-version) doom-version)
(print! (warn "Detected version mismatch in profile loader (%s != %s)"
version doom-version))
(print! (start "Generating profile manifest..."))
(setq recreate? t))
(print-group!
(if (not all?)
(user-error "Individual profile syncing isn't implemented yet")
(let* ((old-profiles (doom-profiles-read doom-profile-cache-file))
(new-profiles (doom-profiles-autodetect))
(load-file doom-profile-load-file)
(version (doom-file-read load-file :by 'read :noerror t))
(recreate? (or (not reload?) (doom-profiles-outdated-p))))
(unless (file-exists-p load-file)
(print! (warn "No profile loader found. Generating one..."))
(print-group! (print! (start "Regenerating it...")))
(setq recreate? t))
(unless (equal (or version doom-version) doom-version)
(print! (warn "Detected version mismatch in profile loader (%s != %s)"
version doom-version))
(print! (start "Generating profile manifest..."))
(setq recreate? t))
(if (not recreate?)
(doom-log "Profiles are up-to-date!")
(let* ((pred (lambda (a b) (eq (car a) (car b))))
@ -68,10 +50,22 @@
(dolist (p added) (print! (item "Added %S") (car p)))
(dolist (p removed) (print! (item "Removed %S") (car p)))
(dolist (p changed) (print! (item "Changed %S") (car p)))
(doom-file-write doom-cli-known-profiles-file (list new-profiles) :mode #o600)
(doom-file-write doom-profile-cache-file (list new-profiles) :mode #o600)
(doom-profiles-write-load-file new-profiles load-file)
(print! (success "Regenerated profile loader: %s")
(path load-file)))))))))
(provide 'doom-cli-profiles)
;;; profiles.el ends here
(defcli-stub! (profile hash) ())
(defcli-stub! (profile new) ())
(defcli-stub! (profile archive) ())
(defcli-stub! (profile (remove rm)) ())
(defcli-stub! (profile (rename mv)) ())
(defcli-stub! (profile nuke) ())
(provide 'doom-cli-profile)
;;; profile.el ends here

View File

@ -56,7 +56,7 @@ OPTIONS:
packages."
:benchmark t
(when (doom-profiles-bootloadable-p)
(call! '(profiles sync "--reload")))
(call! '(profile sync "--all" "--reload")))
(when aot?
(after! straight
(setq straight--native-comp-available t)))

View File

@ -41,6 +41,13 @@ list of paths or profile config files (semi-colon delimited on Windows).")
Can be changed externally by setting $DOOMPROFILELOADFILE.")
(defvar doom-profile-cache-file
(file-name-concat
doom-cache-dir (format "profiles.%s.el" (or (car doom-profile) "@")))
"Where Doom writes its interactive profile loader script.
Can be changed externally by setting $DOOMPROFILELOADFILE.")
(defvar doom-profile-env-file-name "init.env.el"
"TODO")