refactor(cli): rename struct constructors/copiers
To maintain our namespaces.
This commit is contained in:
parent
3a7eab38ad
commit
d231755bdf
2 changed files with 19 additions and 21 deletions
|
@ -181,7 +181,8 @@ the return value of the executed CLI.")
|
||||||
;;
|
;;
|
||||||
;;; `doom-cli'
|
;;; `doom-cli'
|
||||||
|
|
||||||
(cl-defstruct doom-cli
|
(cl-defstruct (doom-cli (:constructor doom-cli-create)
|
||||||
|
(:copier nil))
|
||||||
"An executable CLI command."
|
"An executable CLI command."
|
||||||
(command nil :read-only t)
|
(command nil :read-only t)
|
||||||
type
|
type
|
||||||
|
@ -464,7 +465,8 @@ If RECURSIVE, includes breadcrumbs leading up to COMMANDSPEC."
|
||||||
;;
|
;;
|
||||||
;;; `doom-cli-option'
|
;;; `doom-cli-option'
|
||||||
|
|
||||||
(cl-defstruct doom-cli-option
|
(cl-defstruct (doom-cli-option (:constructor doom-cli-option-create)
|
||||||
|
(:copier nil))
|
||||||
"A switch specification dictating the characteristics of a recognized option."
|
"A switch specification dictating the characteristics of a recognized option."
|
||||||
(symbol nil :read-only t)
|
(symbol nil :read-only t)
|
||||||
docs
|
docs
|
||||||
|
@ -530,7 +532,7 @@ Throws `doom-cli-invalid-option-error' for illegal values."
|
||||||
collect spec)))
|
collect spec)))
|
||||||
|
|
||||||
(defun doom-cli--make-option-generic (symbol spec &optional docs)
|
(defun doom-cli--make-option-generic (symbol spec &optional docs)
|
||||||
(make-doom-cli-option
|
(doom-cli-option-create
|
||||||
:symbol symbol
|
:symbol symbol
|
||||||
:docs docs
|
:docs docs
|
||||||
:switches (doom-cli--read-option-switches spec)
|
:switches (doom-cli--read-option-switches spec)
|
||||||
|
@ -545,7 +547,7 @@ Throws `doom-cli-invalid-option-error' for illegal values."
|
||||||
(signal 'doom-cli-definition-error
|
(signal 'doom-cli-definition-error
|
||||||
(cons "Argument type %s cannot accept arguments for: %s"
|
(cons "Argument type %s cannot accept arguments for: %s"
|
||||||
'&flag (mapconcat #'symbol-name spec ", "))))
|
'&flag (mapconcat #'symbol-name spec ", "))))
|
||||||
(make-doom-cli-option
|
(doom-cli-option-create
|
||||||
:symbol symbol
|
:symbol symbol
|
||||||
:docs docs
|
:docs docs
|
||||||
:flag-p t
|
:flag-p t
|
||||||
|
@ -553,7 +555,7 @@ Throws `doom-cli-invalid-option-error' for illegal values."
|
||||||
:default (car args))))
|
:default (car args))))
|
||||||
|
|
||||||
(defun doom-cli--make-option-multi (symbol spec &optional docs)
|
(defun doom-cli--make-option-multi (symbol spec &optional docs)
|
||||||
(make-doom-cli-option
|
(doom-cli-option-create
|
||||||
:symbol symbol
|
:symbol symbol
|
||||||
:docs docs
|
:docs docs
|
||||||
:multiple-p t
|
:multiple-p t
|
||||||
|
@ -564,7 +566,8 @@ Throws `doom-cli-invalid-option-error' for illegal values."
|
||||||
;;
|
;;
|
||||||
;;; `doom-cli-context'
|
;;; `doom-cli-context'
|
||||||
|
|
||||||
(cl-defstruct doom-cli-context
|
(cl-defstruct (doom-cli-context (:constructor doom-cli-context-create)
|
||||||
|
(:copier doom-cli-context-copy))
|
||||||
"A CLI context, containing all state pertinent to the current session."
|
"A CLI context, containing all state pertinent to the current session."
|
||||||
(init-time before-init-time) ; When this context was created
|
(init-time before-init-time) ; When this context was created
|
||||||
;; A session-specific ID of the current context (defaults to number
|
;; A session-specific ID of the current context (defaults to number
|
||||||
|
@ -876,7 +879,7 @@ considered as well."
|
||||||
(executing-kbd-macro nil)
|
(executing-kbd-macro nil)
|
||||||
(load-read-function #'read)
|
(load-read-function #'read)
|
||||||
(backtrace (doom-backtrace))
|
(backtrace (doom-backtrace))
|
||||||
(context (or context (make-doom-cli-context)))
|
(context (or context (doom-cli-context-create)))
|
||||||
(straight-error
|
(straight-error
|
||||||
(and (bound-and-true-p straight-process-buffer)
|
(and (bound-and-true-p straight-process-buffer)
|
||||||
(stringp data)
|
(stringp data)
|
||||||
|
@ -1063,7 +1066,7 @@ Emacs' batch library lacks an implementation of the exec system call."
|
||||||
(make-directory (file-name-directory context-file) t)
|
(make-directory (file-name-directory context-file) t)
|
||||||
(with-temp-file context-file
|
(with-temp-file context-file
|
||||||
;; DEPRECATED Use `print-unreadable-function' when 28 support is dropped
|
;; DEPRECATED Use `print-unreadable-function' when 28 support is dropped
|
||||||
(let ((newcontext (copy-doom-cli-context context))
|
(let ((newcontext (doom-cli-context-copy context))
|
||||||
(print-level nil)
|
(print-level nil)
|
||||||
(print-length nil)
|
(print-length nil)
|
||||||
(print-circle nil)
|
(print-circle nil)
|
||||||
|
@ -1468,7 +1471,7 @@ ignored.
|
||||||
(dolist (prop '(:autoload :alias :partial :hide))
|
(dolist (prop '(:autoload :alias :partial :hide))
|
||||||
(cl-callf map-delete plist prop))
|
(cl-callf map-delete plist prop))
|
||||||
(puthash (delq nil (cons type target))
|
(puthash (delq nil (cons type target))
|
||||||
(make-doom-cli
|
(doom-cli-create
|
||||||
:command target
|
:command target
|
||||||
:type type
|
:type type
|
||||||
:docs ',(doom-cli--parse-docs docstring)
|
:docs ',(doom-cli--parse-docs docstring)
|
||||||
|
@ -1484,7 +1487,7 @@ ignored.
|
||||||
while (= (length c) (length target))
|
while (= (length c) (length target))
|
||||||
collect (pop commands)))
|
collect (pop commands)))
|
||||||
(puthash (delq nil (cons type alias))
|
(puthash (delq nil (cons type alias))
|
||||||
(make-doom-cli
|
(doom-cli-create
|
||||||
:command alias
|
:command alias
|
||||||
:type type
|
:type type
|
||||||
:docs docs
|
:docs docs
|
||||||
|
@ -1495,7 +1498,7 @@ ignored.
|
||||||
(let ((cli (gethash partial doom-cli--table)))
|
(let ((cli (gethash partial doom-cli--table)))
|
||||||
(when (or (null cli) (doom-cli-autoload cli))
|
(when (or (null cli) (doom-cli-autoload cli))
|
||||||
(puthash (delq nil (cons type partial))
|
(puthash (delq nil (cons type partial))
|
||||||
(make-doom-cli
|
(doom-cli-create
|
||||||
:command partial
|
:command partial
|
||||||
:type type
|
:type type
|
||||||
:docs docs
|
:docs docs
|
||||||
|
@ -1637,7 +1640,7 @@ errors to `doom-cli-error-file')."
|
||||||
(doom-cli--dump
|
(doom-cli--dump
|
||||||
(progn (doom-cli-load-all)
|
(progn (doom-cli-load-all)
|
||||||
(hash-table-values doom-cli--table)))
|
(hash-table-values doom-cli--table)))
|
||||||
(letf! ((context (make-doom-cli-context :prefix prefix))
|
(letf! ((context (doom-cli-context-create :prefix prefix))
|
||||||
(doom-cli--context context)
|
(doom-cli--context context)
|
||||||
(write-logs-fn (doom-partial #'doom-cli--output-write-logs-h context))
|
(write-logs-fn (doom-partial #'doom-cli--output-write-logs-h context))
|
||||||
(show-benchmark-fn (doom-partial #'doom-cli--output-benchmark-h context))
|
(show-benchmark-fn (doom-partial #'doom-cli--output-benchmark-h context))
|
||||||
|
|
|
@ -27,15 +27,6 @@
|
||||||
(kill-emacs 2))
|
(kill-emacs 2))
|
||||||
|
|
||||||
|
|
||||||
;;
|
|
||||||
;;; Variables
|
|
||||||
|
|
||||||
(defvar doom-cli--dump (getenv "__DOOMDUMP")
|
|
||||||
"If non-nil, dump target CLIs to stdout (or all of `doom-cli--table').
|
|
||||||
|
|
||||||
This exists so external tools or Doom binscripts can inspect each other.")
|
|
||||||
|
|
||||||
|
|
||||||
;;
|
;;
|
||||||
;;; Setup CLI session
|
;;; Setup CLI session
|
||||||
|
|
||||||
|
@ -114,5 +105,9 @@ This exists so external tools or Doom binscripts can inspect each other.")
|
||||||
;; Load standard :help and :version handlers.
|
;; Load standard :help and :version handlers.
|
||||||
(load! "cli/help")
|
(load! "cli/help")
|
||||||
|
|
||||||
|
(defcli! (:root :dump) (&args commands)
|
||||||
|
"Dump metadata to stdout for other commands to read."
|
||||||
|
(doom-cli--dump (doom-cli-find commands)))
|
||||||
|
|
||||||
(provide 'core-cli)
|
(provide 'core-cli)
|
||||||
;;; core-cli.el ends here
|
;;; core-cli.el ends here
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue