guix_mirror_bot pushed a commit to branch gnome-team
in repository guix.

commit 727cf55c7eb8298c82be7ea71a15fc7294d0234b
Author: Hilton Chain <[email protected]>
AuthorDate: Wed Feb 26 10:10:10 2025 +0800

    scripts: import: Pass "--insert" to importers.
    
    So that importers can adjust the file before inserting.
    
    * guix/scripts/import.scm (%standard-import-options): Add 
‘--file-to-insert’.
    (guix-import): Pass it to importers when ‘--insert’ is set.
    
    Change-Id: I8e7a18ee8e0f96d7fc5688a207a7a5390ad2fa30
---
 guix/scripts/import.scm | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/guix/scripts/import.scm b/guix/scripts/import.scm
index 3b6d9bf3de..c2f9cbdebf 100644
--- a/guix/scripts/import.scm
+++ b/guix/scripts/import.scm
@@ -25,12 +25,15 @@
 
 (define-module (guix scripts import)
   #:use-module (guix import utils)
+  #:use-module (guix diagnostics)
+  #:use-module (guix i18n)
   #:use-module (guix ui)
   #:use-module (guix scripts)
   #:use-module (guix read-print)
   #:use-module (guix utils)
   #:use-module (srfi srfi-1)
   #:use-module (srfi srfi-26)
+  #:use-module (srfi srfi-37)
   #:use-module (ice-9 format)
   #:use-module (ice-9 match)
   #:export (%standard-import-options
@@ -41,7 +44,14 @@
 ;;; Command line options.
 ;;;
 
-(define %standard-import-options '())
+(define %standard-import-options
+  (list
+   ;; Hidden option for importer-specific file preprocessing.
+   (option '("file-to-insert") #f #t
+           (lambda (opt name arg result)
+             (if (file-exists? arg)
+                 (alist-cons 'file-to-insert arg result)
+                 (leave (G_ "file '~a' does not exist~%") arg))))))
 
 
 ;;;
@@ -152,7 +162,10 @@ PROC callback."
                         (newline port)
                         (newline port)
                         (close-port port)))))))))
-       (import-as-definitions importer args find-and-insert)))
+       (import-as-definitions importer
+                              (cons (string-append "--file-to-insert=" file)
+                                    args)
+                              find-and-insert)))
     ((importer args ...)
      (let ((print (lambda (expr)
                     (leave-on-EPIPE

Reply via email to