34 lines
1.1 KiB
Common Lisp
34 lines
1.1 KiB
Common Lisp
;;;; cl-scopes/config
|
|
|
|
;;;; Utilities for configuration of scopes services.
|
|
|
|
(defpackage :scopes/config
|
|
(:use :common-lisp)
|
|
(:export #:base
|
|
#:override-keys #:env-prefix #:env-path))
|
|
|
|
(in-package :scopes/config)
|
|
|
|
(defclass base ()
|
|
((override-keys :reader override-keys
|
|
:initform nil
|
|
:allocation :class)
|
|
(env-prefix :reader env-prefix
|
|
:initarg :env-prefix
|
|
:initform "SCOPES_")
|
|
(env-path :reader env-path
|
|
:initarg :env-path
|
|
:initform nil)))
|
|
|
|
(defmethod initialize-instance :after ((cfg base) &key &allow-other-keys)
|
|
(let* ((prefix (env-prefix cfg))
|
|
(ep (env-path cfg))
|
|
(dotenv-data (if ep (dotenv:read-env ep))))
|
|
(dolist (sl (override-keys cfg))
|
|
(let* ((key (str:concat prefix (string sl)))
|
|
(env-val (uiop:getenv key))
|
|
(dotenv-val (if dotenv-data (gethash key dotenv-data))))
|
|
(if env-val
|
|
(setf (slot-value cfg sl) env-val)
|
|
(if dotenv-val
|
|
(setf (slot-value cfg sl) dotenv-val)))))))
|