aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2021-05-25 14:06:41 -0700
committerSean Whitton <spwhitton@spwhitton.name>2021-05-25 14:10:13 -0700
commit868f7c4042aa75db58ac00c8bd4948a29b1aee4f (patch)
tree7263c777184a7975c2026def4adff11219c2bd55
parentc5598626d593436e7285728729c178b18a8ffc8d (diff)
downloadconsfigurator-868f7c4042aa75db58ac00c8bd4948a29b1aee4f.tar.gz
add DEFPACKAGE-CONSFIG
Signed-off-by: Sean Whitton <spwhitton@spwhitton.name>
-rw-r--r--doc/introduction.rst14
-rw-r--r--src/package.lisp1
-rw-r--r--src/util.lisp33
3 files changed, 41 insertions, 7 deletions
diff --git a/doc/introduction.rst b/doc/introduction.rst
index 47122d7..656e7eb 100644
--- a/doc/introduction.rst
+++ b/doc/introduction.rst
@@ -28,13 +28,10 @@ Try it out / quick start
(in-package :cl-user)
- (defpackage :com.example.consfig
- (:use #:cl #:alexandria #:consfigurator)
- (:local-nicknames (#:os #:consfigurator.property.os)
- (#:apt #:consfigurator.property.apt)
- (#:cmd #:consfigurator.property.cmd)
- (#:file #:consfigurator.property.file)
- (#:chroot #:consfigurator.property.chroot)))
+ ;; this macro is a simple wrapper of DEFPACKAGE which sets up local
+ ;; nicknames for packages providing properties and data sources
+ (consfigurator:defpackage-consfig :com.example.consfig
+ (:use #:cl #:alexandria #:consfigurator))
4. Define some hosts and deployments.
@@ -282,6 +279,9 @@ recommended package nicknaming schemes for use in consfigs, e.g.::
(#:cmd #:consfigurator.property.cmd)
(#:data.pgp #:consfigurator.data.pgp)))
+You can use the ``DEFPACKAGE-CONSFIG`` macro to set up all these local
+nicknames.
+
Portability and stability
-------------------------
diff --git a/src/package.lisp b/src/package.lisp
index 4edd9a3..61662ef 100644
--- a/src/package.lisp
+++ b/src/package.lisp
@@ -78,6 +78,7 @@
#:in-chroot-pathname
#:escape-sh-token
#:escape-sh-command
+ #:defpackage-consfig
#:*consfigurator-debug-level*
#:with-indented-inform
diff --git a/src/util.lisp b/src/util.lisp
index 1feb97a..79d669c 100644
--- a/src/util.lisp
+++ b/src/util.lisp
@@ -196,6 +196,39 @@ one-dimensional collections of values."
(re:scan-to-strings "^uid=[0-9]+\\(([^)]+)" output)
(and match (elt groups 0))))
+;; not DEFCONSFIG because a consfig is a system not a package
+(defmacro defpackage-consfig (name &body forms)
+ "Convenience wrapper around DEFPACKAGE for consfigs.
+Adds recommended local nicknames for all the property and data source packages
+that come with Consfigurator. Either use this directly or use its macro
+expansion as a starting point for your own DEFPACKAGE form for your consfig."
+ (let ((forms (copy-list forms))
+ (local-nicknames
+ (cons :local-nicknames
+ (loop for package in (list-all-packages)
+ for name = (package-name package)
+ if (string-prefix-p "CONSFIGURATOR.PROPERTY." name)
+ collect (list (make-symbol (subseq name 23))
+ (make-symbol name))
+ else if (string-prefix-p "CONSFIGURATOR.DATA." name)
+ collect (list (make-symbol (subseq name 14))
+ (make-symbol name))))))
+ (if-let ((form (loop for form on forms
+ when (and (listp (car form))
+ (eql :local-nicknames (caar form)))
+ return form)))
+ (rplaca form (nconc local-nicknames (cdar form)))
+ (push local-nicknames forms))
+ ;; Not much benefit to importing CONSFIGURATOR for the user as it only
+ ;; needs to be done once, and some users will prefer to import qualified,
+ ;; but we could also have:
+ ;; (if-let ((form (loop for form on forms
+ ;; when (and (listp (car form)) (eql :use (caar form)))
+ ;; return form)))
+ ;; (rplaca form (list* :use '#:consfigurator (cdar form)))
+ ;; (push '(:use '#:cl '#:consfigurator) forms))
+ `(defpackage ,name ,@forms)))
+
;;;; Progress & debug printing