diff options
-rw-r--r-- | hyperquirks.lisp | 11 |
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) |