fix(cli): aliases to pseudo commands

To understand what's going on here, understand this: this is a regular
CLI command:

  (defcli! (doom sync) () ...)

And this is a pseudo command:

  (defcli! (:before doom sync) () ...)

If a pseudo command is aliased to another pseudo command:

  (defcli! (:before doom (foo bar baz)) ...)

In which case, ':before doom bar' and ':before doom baz' are aliases for
':before doom foo', there was a bug that cut out the keyword, so in
actuality, ':before doom {bar,baz}' were aliased to 'doom bar'.

This fixes that, and the peculiar issue of 'doom purge' executing 'doom
build' due to this, living in core/cli/packages.el:

  (defcli! (:before (build b purge p)) (&context context)
    (require 'comp nil t)
    (doom-initialize-core-packages))

Ref: https://github.com/doomemacs/doomemacs/issues/4273#issuecomment-1159610824
This commit is contained in:
Henrik Lissner 2022-06-19 21:26:53 +02:00
parent 92a5c28687
commit d226946f59
No known key found for this signature in database
GPG key ID: B60957CA074D39A3

View file

@ -270,18 +270,18 @@ COMMAND can be a command path (list of strings), a `doom-cli' struct, or a
Returned in the order they will execute. Includes pseudo CLIs."
(let* ((command (doom-cli--command command))
(pseudo? (keywordp (car-safe command)))
(paths (doom-cli--command-expand command t))
results)
(unless pseudo?
(dolist (path paths)
(push (cons :before path) results)))
(paths (nreverse (doom-cli--command-expand command t)))
results clis)
(push '(:after) results)
(dolist (path paths)
(push (cons :after path) results))
(push command results)
(unless pseudo?
(dolist (path (reverse paths))
(push (cons :after path) results)))
(setq results (delq nil (mapcar #'doom-cli-get results))
results (nreverse (delete-dups results)))))
(dolist (path (nreverse paths))
(push (cons :before path) results))
(push '(:before) results)
(dolist (result (nreverse results) clis)
(when-let (cli (doom-cli-get result))
(cl-pushnew cli clis :test #'equal :key #'doom-cli-key)))))
(defun doom-cli-prop (cli prop &optional null-value)
"Returns a PROPerty of CLI's plist, or NULL-VALUE if it doesn't exist."
@ -1485,7 +1485,7 @@ ignored.
:command alias
:type type
:docs docs
:alias target
:alias (delq nil (cons type target))
:plist (append plist '(:hide t)))
doom-cli--table))
(dolist (partial commands)