fix(cli): doom-cli-context persistence

20d5440 introduced a regression where options would be lost when a CLI
session is restarted. :config literate users, for example, would run
'doom sync -u' only for the -u option to be ignored, because it was
discarded after the literate module restarts the session.

Amend: 20d5440023
This commit is contained in:
Henrik Lissner 2022-08-05 00:27:23 +02:00
parent ba668f7cb0
commit 2254b8c561
No known key found for this signature in database
GPG key ID: B60957CA074D39A3

View file

@ -608,9 +608,9 @@ Throws `doom-cli-invalid-option-error' for illegal values."
(prefix "@") ; The basename of the script creating this context (prefix "@") ; The basename of the script creating this context
meta-p ; Whether or not this is a help/meta request meta-p ; Whether or not this is a help/meta request
error ; error ;
command ; The full command that led to this context (command nil :skip t) ; The full command that led to this context
path ; Breadcrumb list of resolved commands so far (path nil :skip t) ; Breadcrumb list of resolved commands so far
whole ; Unfiltered and unprocessed list of arguments (whole nil :skip t) ; Unfiltered and unprocessed list of arguments
(options nil :skip t) ; An alist of (flags . value) (options nil :skip t) ; An alist of (flags . value)
(arguments nil :skip t) ; An alist of non-subcommand arguments, by command (arguments nil :skip t) ; An alist of non-subcommand arguments, by command
(stdin (generate-new-buffer " *doom-cli stdin*") :type buffer) ; buffer containing anything piped into this session (stdin (generate-new-buffer " *doom-cli stdin*") :type buffer) ; buffer containing anything piped into this session
@ -688,8 +688,8 @@ executable context."
(_ old-value)))))) (_ old-value))))))
(run-hook-with-args 'doom-cli-create-context-functions context) (run-hook-with-args 'doom-cli-create-context-functions context)
(delete-file file) (delete-file file)
(doom-log "Restored context: %s" (doom-cli-context-pid context)) (doom-log "Restored context: %s" (doom-cli-context-pid context))))
context))) context)
(defun doom-cli-context-parse (args context) (defun doom-cli-context-parse (args context)
"Parse ARGS and update CONTEXT to reflect it." "Parse ARGS and update CONTEXT to reflect it."
@ -1746,9 +1746,8 @@ errors to `doom-cli-error-file')."
(doom-cli--exit (doom-cli--exit
(condition-case e (condition-case e
(let* ((args (cons (if (getenv "__DOOMDUMP") :dump prefix) args)) (let* ((args (cons (if (getenv "__DOOMDUMP") :dump prefix) args))
(context (context (doom-cli-context-restore (getenv "__DOOMCONTEXT") context))
(or (doom-cli-context-restore (getenv "__DOOMCONTEXT") context) (context (doom-cli-context-parse args context)))
(doom-cli-context-parse args context))))
(run-hook-with-args 'doom-cli-before-run-functions context) (run-hook-with-args 'doom-cli-before-run-functions context)
(let ((result (doom-cli-context-execute context))) (let ((result (doom-cli-context-execute context)))
(run-hook-with-args 'doom-cli-after-run-functions context result)) (run-hook-with-args 'doom-cli-after-run-functions context result))