refactor!(cli): rename cli definers for consistency

BREAKING CHANGE: If anyone is using Doom's CLI framework and are
defining their own CLIs with any of the following macros, they'll need
to be updated to their new names:

- defautoload! -> defcli-autoload!
- defgroup! -> defcli-group!
- defstub! -> defcli-stub!
- defalias! -> defcli-alias!
- defobsolete! -> defcli-obsolete!

These were renamed to make their relationship with CLIs more obvious;
they were too ambiguous otherwise.
This commit is contained in:
Henrik Lissner 2022-09-10 23:23:29 +02:00
parent 0ce2989d86
commit bcf7a8a554
No known key found for this signature in database
GPG key ID: B60957CA074D39A3
7 changed files with 35 additions and 35 deletions

View file

@ -246,22 +246,22 @@ SEE ALSO:
;; Library for generating autoloads files for Doom modules & packages. ;; Library for generating autoloads files for Doom modules & packages.
(load! "autoloads" dir) (load! "autoloads" dir)
(defgroup! (defcli-group!
:prefix 'doom :prefix 'doom
;; Import this for implicit 'X help' commands for your script: ;; Import this for implicit 'X help' commands for your script:
(defalias! ((help h)) (:root :help)) (defcli-alias! ((help h)) (:root :help))
;; And suggest its use when errors occur. ;; And suggest its use when errors occur.
(add-to-list 'doom-help-commands "%p h[elp] %c") (add-to-list 'doom-help-commands "%p h[elp] %c")
(defgroup! "Config Management" (defcli-group! "Config Management"
:docs "Commands for maintaining your Doom Emacs configuration." :docs "Commands for maintaining your Doom Emacs configuration."
(defautoload! ((sync s))) (defcli-autoload! ((sync s)))
(defautoload! ((upgrade up))) (defcli-autoload! ((upgrade up)))
(defautoload! (env)) (defcli-autoload! (env))
(defautoload! ((build b purge p rollback)) "packages") (defcli-autoload! ((build b purge p rollback)) "packages")
(defautoload! ((install i))) (defcli-autoload! ((install i)))
(defautoload! ((compile c))) (defcli-autoload! ((compile c)))
(defautoload! (clean) "compile") (defcli-autoload! (clean) "compile")
;; TODO Post-3.0 commands ;; TODO Post-3.0 commands
;; (load! "gc" dir) ;; (load! "gc" dir)
@ -269,31 +269,31 @@ SEE ALSO:
;; (load! "nuke" dir) ;; (load! "nuke" dir)
;; (load! "package" dir) ;; (load! "package" dir)
;; (load! "profile" dir) ;; (load! "profile" dir)
;; (defobsolete! ((compile c)) (sync "--compile") "v3.0.0") ;; (defcli-obsolete! ((compile c)) (sync "--compile") "v3.0.0")
;; (defobsolete! ((build b)) (sync "--rebuild") "v3.0.0") ;; (defcli-obsolete! ((build b)) (sync "--rebuild") "v3.0.0")
) )
(defgroup! "Diagnostics" (defcli-group! "Diagnostics"
:docs "Commands for troubleshooting and debugging Doom." :docs "Commands for troubleshooting and debugging Doom."
(defautoload! ((doctor doc))) (defcli-autoload! ((doctor doc)))
(defautoload! (info)) (defcli-autoload! (info))
(defalias! ((version v)) (:root :version))) (defcli-alias! ((version v)) (:root :version)))
(defgroup! "Development" (defcli-group! "Development"
:docs "Commands for developing or launching Doom." :docs "Commands for developing or launching Doom."
(defautoload! (ci)) (defcli-autoload! (ci))
(defautoload! (make)) (defcli-autoload! (make))
(defautoload! (run)) (defcli-autoload! (run))
;; FIXME Test framework ;; FIXME Test framework
;; (load! "test" dir) ;; (load! "test" dir)
) )
(let ((cli-file "cli")) (let ((cli-file "cli"))
(defgroup! "Module commands" (defcli-group! "Module commands"
(dolist (key (hash-table-keys doom-modules)) (dolist (key (hash-table-keys doom-modules))
(when-let (path (plist-get (gethash key doom-modules) :path)) (when-let (path (plist-get (gethash key doom-modules) :path))
(defgroup! :prefix (format "+%s" (cdr key)) (defcli-group! :prefix (format "+%s" (cdr key))
(load! cli-file path t))))) (load! cli-file path t)))))
(doom-log "Loading $DOOMDIR/cli.el") (doom-log "Loading $DOOMDIR/cli.el")

View file

@ -5,7 +5,7 @@
;; command is passed with -?, --help, or --version. They can also be aliased to ;; command is passed with -?, --help, or --version. They can also be aliased to
;; a sub-command to make more of its capabilities accessible to users, with: ;; a sub-command to make more of its capabilities accessible to users, with:
;; ;;
;; (defalias! (myscript (help h)) (:help)) ;; (defcli-alias! (myscript (help h)) (:help))
;; ;;
;; You can define your own command-specific help handlers, e.g. ;; You can define your own command-specific help handlers, e.g.
;; ;;

View file

@ -68,7 +68,7 @@ OPTIONS:
(write-region (buffer-string) nil codeowners-file))))) (write-region (buffer-string) nil codeowners-file)))))
;; TODO Finish me ;; TODO Finish me
(defstub! (make changelog)) (defcli-stub! (make changelog))

View file

@ -60,7 +60,7 @@ list remains lean."
(doom-autoloads-reload)) (doom-autoloads-reload))
t) t)
(defstub! rollback) ; TODO Implement me post-3.0 (defcli-stub! rollback) ; TODO Implement me post-3.0
;; ;;

View file

@ -18,7 +18,7 @@
;; ;;
;;; Commands ;;; Commands
(defalias! (:before (sync s)) (:before build)) (defcli-alias! (:before (sync s)) (:before build))
(defcli! ((sync s)) (defcli! ((sync s))
((noenvvar? ("-e") "Don't regenerate the envvar file") ((noenvvar? ("-e") "Don't regenerate the envvar file")

View file

@ -32,7 +32,7 @@ Should be one of:
;;; Commands ;;; Commands
;; FIXME Will be fixed in v3.1 ;; FIXME Will be fixed in v3.1
(defstub! test (defcli-stub! test
((backend ("--ert" "--buttercup")) ((backend ("--ert" "--buttercup"))
(jobs ("-j" "--jobs" int)) (jobs ("-j" "--jobs" int))
&rest targets) &rest targets)

View file

@ -347,7 +347,7 @@ struct."
(defun doom-cli-get (command &optional noresolve? noload?) (defun doom-cli-get (command &optional noresolve? noload?)
"Return CLI at COMMAND. "Return CLI at COMMAND.
Will autoload COMMAND if it was deferred with `defautoload!'. Will autoload COMMAND if it was deferred with `defcli-autoload!'.
If NORESOLVE?, don't follow aliases." If NORESOLVE?, don't follow aliases."
(when-let* ((command (doom-cli--command command)) (when-let* ((command (doom-cli--command command))
@ -1475,7 +1475,7 @@ treated as a list of aliases for the command. For example:
COMMANDSPEC may be prefixed with any of these special keywords: COMMANDSPEC may be prefixed with any of these special keywords:
:root ... :root ...
This command will ignore any :prefix set by a parent `defgroup!'. This command will ignore any :prefix set by a parent `defcli-group!'.
:before ... :before ...
This command will run before the specified command(s). This command will run before the specified command(s).
:after ... :after ...
@ -1655,7 +1655,7 @@ properties:
an 'unknown command' error. an 'unknown command' error.
:prefix (STR...) :prefix (STR...)
A command path to prepend to the command name. This is more useful as part A command path to prepend to the command name. This is more useful as part
of `defgroup!'s inheritance. of `defcli-group!'s inheritance.
The BODY of commands with a non-nil :alias, :disable, or :partial will be The BODY of commands with a non-nil :alias, :disable, or :partial will be
ignored. ignored.
@ -1747,14 +1747,14 @@ ignored.
doom-cli--table))))) doom-cli--table)))))
target)))))) target))))))
(defmacro defalias! (commandspec target &rest plist) (defmacro defcli-alias! (commandspec target &rest plist)
"Define a CLI alias for TARGET at COMMANDSPEC. "Define a CLI alias for TARGET at COMMANDSPEC.
See `defcli!' for information about COMMANDSPEC. See `defcli!' for information about COMMANDSPEC.
TARGET is not a command specification, and should be a command list." TARGET is not a command specification, and should be a command list."
`(defcli! ,commandspec () :alias ',target ,@plist)) `(defcli! ,commandspec () :alias ',target ,@plist))
(defmacro defobsolete! (commandspec target when) (defmacro defcli-obsolete! (commandspec target when)
"Define an obsolete CLI COMMANDSPEC that refers users to NEW-COMMAND. "Define an obsolete CLI COMMANDSPEC that refers users to NEW-COMMAND.
See `defcli!' for information about COMMANDSPEC. See `defcli!' for information about COMMANDSPEC.
@ -1771,7 +1771,7 @@ WHEN specifies what version this command was rendered obsolete."
(doom-cli-command-string ncommand)) (doom-cli-command-string ncommand))
(call! ',target args)))) (call! ',target args))))
(defmacro defstub! (commandspec &optional _argspec &rest body) (defmacro defcli-stub! (commandspec &optional _argspec &rest body)
"Define a stub CLI, which will throw an error if invoked. "Define a stub CLI, which will throw an error if invoked.
Use this to define commands that will eventually be implemented, but haven't Use this to define commands that will eventually be implemented, but haven't
@ -1783,7 +1783,7 @@ yet. They won't be included in command listings (by help documentation)."
:hide t :hide t
(user-error "Command not implemented yet"))) (user-error "Command not implemented yet")))
(defmacro defautoload! (commandspec &optional path &rest plist) (defmacro defcli-autoload! (commandspec &optional path &rest plist)
"Defer loading of PATHS until PREFIX is called." "Defer loading of PATHS until PREFIX is called."
`(let* ((doom-cli--plist (append (list ,@plist) doom-cli--plist)) `(let* ((doom-cli--plist (append (list ,@plist) doom-cli--plist))
(commandspec (doom-cli-command-normalize ',commandspec)) (commandspec (doom-cli-command-normalize ',commandspec))
@ -1799,7 +1799,7 @@ yet. They won't be included in command listings (by help documentation)."
(doom-cli-autoload cli)) (doom-cli-autoload cli))
(defcli! ,commandspec () :autoload path)))) (defcli! ,commandspec () :autoload path))))
(defmacro defgroup! (&rest body) (defmacro defcli-group! (&rest body)
"Declare common properties for any CLI commands defined in BODY." "Declare common properties for any CLI commands defined in BODY."
(when (stringp (car body)) (when (stringp (car body))
(push :group body)) (push :group body))