diff options
| author | Craig Jennings <c@cjennings.net> | 2026-04-19 07:08:22 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-04-19 07:08:22 -0500 |
| commit | 13c057a75ce6d92f9de7e1d53d0ae2554261cb2e (patch) | |
| tree | e1f8fe58b7ef77af9d9ded2cee64f1fe5f690fe5 /modules/transcription-config.el | |
| parent | 85d9127ea6a5cd624dd4567618ce87b12e491e8c (diff) | |
| download | dotemacs-13c057a75ce6d92f9de7e1d53d0ae2554261cb2e.tar.gz dotemacs-13c057a75ce6d92f9de7e1d53d0ae2554261cb2e.zip | |
refactor(transcription): extract cj/--build-process-environment
Pull the per-backend env-var assembly out of cj/--start-transcription-process
into a standalone pure function. 9 tests cover: the three backends, parent-env
preservation, non-mutation, missing-key user-error, unknown-backend error.
Diffstat (limited to 'modules/transcription-config.el')
| -rw-r--r-- | modules/transcription-config.el | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/modules/transcription-config.el b/modules/transcription-config.el index 2adbaa4d..69111a11 100644 --- a/modules/transcription-config.el +++ b/modules/transcription-config.el @@ -118,6 +118,20 @@ Returns the password string, or nil if no matching entry exists." (funcall secret) secret))) +(defun cj/--build-process-environment (backend) + "Return `process-environment' augmented with BACKEND's API-key env var. +If BACKEND needs no API key (no :auth-host in its descriptor), return +`process-environment' unchanged. Signals `user-error' if BACKEND requires +a key but none is found in authinfo.gpg." + (let* ((desc (cj/--backend-plist backend)) + (auth-host (plist-get desc :auth-host)) + (env-var (plist-get desc :env-var))) + (if (and auth-host env-var) + (if-let ((api-key (cj/--auth-source-password auth-host))) + (cons (format "%s=%s" env-var api-key) process-environment) + (user-error "API key not found in authinfo.gpg for host %s" auth-host)) + process-environment))) + ;; ---------------------------- Process Management ----------------------------- (defun cj/--notify (title message &optional urgency) @@ -158,15 +172,7 @@ Returns the process object." (format "Script: %s\n\n" script))) ;; Start process with environment - (let* ((process-environment - (let* ((desc (cj/--backend-plist cj/transcribe-backend)) - (auth-host (plist-get desc :auth-host)) - (env-var (plist-get desc :env-var))) - (if (and auth-host env-var) - (if-let ((api-key (cj/--auth-source-password auth-host))) - (cons (format "%s=%s" env-var api-key) process-environment) - (user-error "API key not found in authinfo.gpg for host %s" auth-host)) - process-environment))) + (let* ((process-environment (cj/--build-process-environment cj/transcribe-backend)) (process (make-process :name process-name :buffer (get-buffer-create buffer-name) |
