refactor(cli): simplify struct definitions
There's no need to be this meticulous. It only pads the line count, and for little merit.
This commit is contained in:
parent
8971ee36e5
commit
6dfed1ff47
1 changed files with 11 additions and 14 deletions
|
@ -228,8 +228,7 @@ the return value of the executed CLI.")
|
||||||
;;
|
;;
|
||||||
;;; `doom-cli'
|
;;; `doom-cli'
|
||||||
|
|
||||||
(cl-defstruct (doom-cli (:constructor doom-cli-create)
|
(cl-defstruct doom-cli
|
||||||
(:copier nil))
|
|
||||||
"An executable CLI command."
|
"An executable CLI command."
|
||||||
(command nil :read-only t)
|
(command nil :read-only t)
|
||||||
type
|
type
|
||||||
|
@ -522,8 +521,7 @@ If RECURSIVE, includes breadcrumbs leading up to COMMANDSPEC."
|
||||||
;;
|
;;
|
||||||
;;; `doom-cli-option'
|
;;; `doom-cli-option'
|
||||||
|
|
||||||
(cl-defstruct (doom-cli-option (:constructor doom-cli-option-create)
|
(cl-defstruct doom-cli-option
|
||||||
(: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
|
||||||
|
@ -589,7 +587,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)
|
||||||
(doom-cli-option-create
|
(make-doom-cli-option
|
||||||
:symbol symbol
|
:symbol symbol
|
||||||
:docs docs
|
:docs docs
|
||||||
:switches (doom-cli--read-option-switches spec)
|
:switches (doom-cli--read-option-switches spec)
|
||||||
|
@ -604,7 +602,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 ", "))))
|
||||||
(doom-cli-option-create
|
(make-doom-cli-option
|
||||||
:symbol symbol
|
:symbol symbol
|
||||||
:docs docs
|
:docs docs
|
||||||
:flag-p t
|
:flag-p t
|
||||||
|
@ -612,7 +610,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)
|
||||||
(doom-cli-option-create
|
(make-doom-cli-option
|
||||||
:symbol symbol
|
:symbol symbol
|
||||||
:docs docs
|
:docs docs
|
||||||
:multiple-p t
|
:multiple-p t
|
||||||
|
@ -623,8 +621,7 @@ Throws `doom-cli-invalid-option-error' for illegal values."
|
||||||
;;
|
;;
|
||||||
;;; `doom-cli-context'
|
;;; `doom-cli-context'
|
||||||
|
|
||||||
(cl-defstruct (doom-cli-context (:constructor doom-cli-context-create)
|
(cl-defstruct doom-cli-context
|
||||||
(: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
|
||||||
|
@ -948,7 +945,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 (doom-cli-context-create)))
|
(context (or context (make-doom-cli-context)))
|
||||||
(straight-error
|
(straight-error
|
||||||
(and (bound-and-true-p straight-process-buffer)
|
(and (bound-and-true-p straight-process-buffer)
|
||||||
(or (member straight-process-buffer data)
|
(or (member straight-process-buffer data)
|
||||||
|
@ -1588,7 +1585,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))
|
||||||
(doom-cli-create
|
(make-doom-cli
|
||||||
:command target
|
:command target
|
||||||
:type type
|
:type type
|
||||||
:docs (doom-cli--parse-docs (or ',docstring docs))
|
:docs (doom-cli--parse-docs (or ',docstring docs))
|
||||||
|
@ -1604,7 +1601,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))
|
||||||
(doom-cli-create
|
(make-doom-cli
|
||||||
:command alias
|
:command alias
|
||||||
:type type
|
:type type
|
||||||
:docs docs
|
:docs docs
|
||||||
|
@ -1616,7 +1613,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))
|
||||||
(doom-cli-create
|
(make-doom-cli
|
||||||
:command partial
|
:command partial
|
||||||
:type type
|
:type type
|
||||||
:docs docs
|
:docs docs
|
||||||
|
@ -1772,7 +1769,7 @@ errors to `doom-cli-error-file')."
|
||||||
(when doom-cli--context
|
(when doom-cli--context
|
||||||
(error "Cannot nest `run!' calls"))
|
(error "Cannot nest `run!' calls"))
|
||||||
(letf! ((args (flatten-list args))
|
(letf! ((args (flatten-list args))
|
||||||
(context (doom-cli-context-create :prefix prefix :whole args))
|
(context (make-doom-cli-context :prefix prefix :whole args))
|
||||||
(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))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue