aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2021-02-24 10:47:29 -0700
committerSean Whitton <spwhitton@spwhitton.name>2021-02-24 10:47:29 -0700
commit9490953e268b89f4219ed9f724e71cc6e4526665 (patch)
treeb01f1e4d6ae04e330b923aff02b2ba0f81c2f0a2
parenta8a666f045ab7a5966d11cb2eac12ef099f23960 (diff)
downloadconsfigurator-9490953e268b89f4219ed9f724e71cc6e4526665.tar.gz
add FILE:REGEX-REPLACE-LINES
Signed-off-by: Sean Whitton <spwhitton@spwhitton.name>
-rw-r--r--src/package.lisp4
-rw-r--r--src/property/file.lisp11
2 files changed, 14 insertions, 1 deletions
diff --git a/src/package.lisp b/src/package.lisp
index d40f464..c641ae9 100644
--- a/src/package.lisp
+++ b/src/package.lisp
@@ -146,10 +146,12 @@
(defpackage :consfigurator.property.file
(:use #:cl #:consfigurator #:alexandria)
+ (:local-nicknames (#:re #:cl-ppcre))
(:export #:has-content
#:contains-lines
#:data-uploaded
- #:host-data-uploaded))
+ #:host-data-uploaded
+ #:regex-replace-lines))
(defpackage :consfigurator.data.asdf
(:use #:cl #:consfigurator))
diff --git a/src/property/file.lisp b/src/property/file.lisp
index c3eaab5..ac997d3 100644
--- a/src/property/file.lisp
+++ b/src/property/file.lisp
@@ -42,3 +42,14 @@
(require-data (get-hostname) destination))
(:apply
(data-uploaded (get-hostname) destination destination)))
+
+(defprop regex-replace-lines :posix (regex replace file)
+ "Like s/REGEX/REPLACE/ on the lines of FILE.
+Uses CL-PPCRE:REGEX-REPLACE, which see for the syntax of REPLACE."
+ (:apply
+ (writefile
+ file
+ (unlines
+ (mapcar (lambda (line)
+ (re:regex-replace regex line replace))
+ (lines (readfile file)))))))