services: configuration: Allow disabling serialization.
Serialization is not always useful, for example when deriving command line arguments from a configuration. This change provides a way to turn it off, which removes the need to define a bunch of dummy serialization procedures. Credit goes to Andrew Gierth (RhodiumToad) from #guile for providing the solution. Thank you! * gnu/services/configuration.scm (define-configuration-helper): New procedure. (define-configuration) <no-serialization>: New syntactic keyword. Use it in a new pattern. Refactor the macro so that it makes use of the above helper procedure.
This commit is contained in:
parent
1a2704add3
commit
3f9a12dc08
|
@ -116,9 +116,8 @@ (define (maybe-stem? val)
|
||||||
(define (serialize-maybe-stem field-name val)
|
(define (serialize-maybe-stem field-name val)
|
||||||
(if (stem? val) (serialize-stem field-name val) ""))))))))
|
(if (stem? val) (serialize-stem field-name val) ""))))))))
|
||||||
|
|
||||||
(define-syntax define-configuration
|
(define (define-configuration-helper serialize? syn)
|
||||||
(lambda (stx)
|
(syntax-case syn ()
|
||||||
(syntax-case stx ()
|
|
||||||
((_ stem (field (field-type def ...) doc) ...)
|
((_ stem (field (field-type def ...) doc) ...)
|
||||||
(with-syntax (((field-getter ...)
|
(with-syntax (((field-getter ...)
|
||||||
(map (lambda (field)
|
(map (lambda (field)
|
||||||
|
@ -139,7 +138,9 @@ (define-syntax define-configuration
|
||||||
#'((field-type def ...) ...)))
|
#'((field-type def ...) ...)))
|
||||||
((field-serializer ...)
|
((field-serializer ...)
|
||||||
(map (lambda (type)
|
(map (lambda (type)
|
||||||
(id #'stem #'serialize- type))
|
(if serialize?
|
||||||
|
(id #'stem #'serialize- type)
|
||||||
|
#f))
|
||||||
#'(field-type ...))))
|
#'(field-type ...))))
|
||||||
#`(begin
|
#`(begin
|
||||||
(define-record-type* #,(id #'stem #'< #'stem #'>)
|
(define-record-type* #,(id #'stem #'< #'stem #'>)
|
||||||
|
@ -178,7 +179,17 @@ (define-syntax-rule (stem arg (... ...))
|
||||||
(let ((conf (#,(id #'stem #'% #'stem) arg (... ...))))
|
(let ((conf (#,(id #'stem #'% #'stem) arg (... ...))))
|
||||||
(validate-configuration conf
|
(validate-configuration conf
|
||||||
#,(id #'stem #'stem #'-fields))
|
#,(id #'stem #'stem #'-fields))
|
||||||
conf))))))))
|
conf)))))))
|
||||||
|
|
||||||
|
(define-syntax define-configuration
|
||||||
|
(lambda (s)
|
||||||
|
(syntax-case s (no-serialization)
|
||||||
|
((_ stem (field (field-type def ...) doc) ... (no-serialization))
|
||||||
|
(define-configuration-helper
|
||||||
|
#f #'(_ stem (field (field-type def ...) doc) ...)))
|
||||||
|
((_ stem (field (field-type def ...) doc) ...)
|
||||||
|
(define-configuration-helper
|
||||||
|
#t #'(_ stem (field (field-type def ...) doc) ...))))))
|
||||||
|
|
||||||
(define (serialize-package field-name val)
|
(define (serialize-package field-name val)
|
||||||
"")
|
"")
|
||||||
|
|
Loading…
Reference in a new issue