gwl-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 3/3] graph: Add output switch


From: Olivier Dion
Subject: [PATCH 3/3] graph: Add output switch
Date: Mon, 6 Jun 2022 15:49:00 -0400

---
 gwl/config.scm.in |  9 ++++++++-
 gwl/main.scm      | 13 ++++++++++++-
 2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/gwl/config.scm.in b/gwl/config.scm.in
index 728eec5..1e0b4d0 100644
--- a/gwl/config.scm.in
+++ b/gwl/config.scm.in
@@ -148,7 +148,14 @@ workflow.")
 format) of the specified workflow.")
       (keywords
        (list
-        log-event-switch))
+        log-event-switch
+        (switch
+         (name 'output)
+         (character #\o)
+         (default #false)
+         (test string?)
+         (synopsis "Write dot graph to <file>.")
+         (example "<file>"))))
       (arguments
        (list
         (argument
diff --git a/gwl/main.scm b/gwl/main.scm
index 78494fd..7f0fd14 100644
--- a/gwl/main.scm
+++ b/gwl/main.scm
@@ -17,6 +17,7 @@
 (define-module (gwl main)
   #:use-module (config)
   #:use-module (config api)
+  #:use-module ((guix build utils) #:select (mkdir-p))
   #:use-module (gwl errors)
   #:use-module (gwl process-engines)
   #:use-module (gwl web-interface)
@@ -95,5 +96,15 @@
            (parameterize ((*current-filename* file-name))
              (match (load-workflow file-name)
                ((? workflow? wf)
-                (format #t "~a\n" (workflow->dot wf)))
+
+                (define (flush)
+                  (format #t "~a\n" (workflow->dot wf)))
+
+                (define output (%config 'output))
+
+                (if output
+                    (begin
+                      (mkdir-p (dirname output))
+                      (with-output-to-file output flush))
+                    (flush)))
                (_ (leave (G_ "Failed to process the workflow.~%")))))))))))
-- 
2.36.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]