summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcolin <colin@cicadas.surf>2023-03-09 18:42:39 -0800
committercolin <colin@cicadas.surf>2023-03-09 18:42:39 -0800
commit92cd04b4242dd8cf47237569a662a6791de0360b (patch)
treedaa26a578264451c828c4cc2751b306e60157a0f
parente3a0914526900f3189fa07574bade13098e775c1 (diff)
Add docstring to with-env
-rw-r--r--hyperquirks.lisp11
1 files changed, 10 insertions, 1 deletions
diff --git a/hyperquirks.lisp b/hyperquirks.lisp
index 70584a5..8fdbe54 100644
--- a/hyperquirks.lisp
+++ b/hyperquirks.lisp
@@ -5,11 +5,20 @@
;;; MACROS
(defmacro with-env ((&rest bindings) &body body)
+ "Execute BODY in context where environment variables are bound to
+particular values. When BODY finishes executing, or exits early, the
+environment variables are restored to their original values.
+
+EXAMPLE:
+
+(with-env ((\"VAR1\" (get-value-for-var))
+ (\"VAR2\" \"SOME_VAL\"))
+ (do-stuff-with-environment))"
(let ((bindings
(loop :for binding :in bindings
:collect (list* (gensym "VAR") (gensym "VAL") binding))))
`(let* ,(loop :for (oldval cacheval envvar newval) :in bindings
- :collect `(,oldval (uiop:getenv ,envvar))
+ :collect `(,oldval (or (uiop:getenv ,envvar) ""))
:collect `(,cacheval ,newval))
(setf ,@(loop :for (oldval cacheval envvar newval) :in bindings
:collect `(uiop:getenv ,envvar)