about summary refs log tree commit diff
path: root/scripts
diff options
context:
space:
mode:
authorArun Isaac2025-12-02 01:18:04 +0000
committerArun Isaac2025-12-02 01:19:11 +0000
commit8eb8fde7cf6da312074f6704b111ea8e4a9df3b7 (patch)
tree2fca8561a17611b0f27593413a36dc9cccb59749 /scripts
parentceb555dd124dc18e2dad747b9afb2987cdbb91db (diff)
downloadccwl-8eb8fde7cf6da312074f6704b111ea8e4a9df3b7.tar.gz
ccwl-8eb8fde7cf6da312074f6704b111ea8e4a9df3b7.tar.lz
ccwl-8eb8fde7cf6da312074f6704b111ea8e4a9df3b7.zip
scripts: Add --output option.
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/ccwl24
1 files changed, 18 insertions, 6 deletions
diff --git a/scripts/ccwl b/scripts/ccwl
index e68501f..c77968a 100755
--- a/scripts/ccwl
+++ b/scripts/ccwl
@@ -28,6 +28,7 @@ exec guile --no-auto-compile -e main -s "$0" "$@"
 
 (use-modules (rnrs conditions)
              (rnrs exceptions)
+             (srfi srfi-26)
              (srfi srfi-28)
              (srfi srfi-37)
              (ice-9 match)
@@ -65,11 +66,14 @@ exec guile --no-auto-compile -e main -s "$0" "$@"
                                  #f)))
                   (acons 'to (string->symbol arg)
                          result)))
+        (option (list #\o "output") #t #f
+                (lambda (opt name arg result)
+                  (acons 'output-file arg result)))
         %help-option))
 
-(define (ccwl-compile source to)
-  "Compile @var{source} file to @var{to} format. @var{to} is either
-@code{'cwl} or @code{'dot}."
+(define (ccwl-compile source to port)
+  "Compile @var{source} file to @var{to} format writing output to
+@var{port}. @var{to} is either @code{'cwl} or @code{'dot}."
   ;; We don't need to compile ccwl files. Loading is sufficient for
   ;; our purposes. Besides, compiling would fail since the workflow
   ;; macro cannot access command definitions.
@@ -92,7 +96,7 @@ exec guile --no-auto-compile -e main -s "$0" "$@"
          (raise-exception
           (condition (formatted-message "Last expression in file ~a returns none of workflow, command or js-expression"
                                         source)))))
-   (current-output-port)))
+   port))
 
 (define (main args)
   (with-exception-handler
@@ -130,6 +134,7 @@ Thank you!
              (display (format "Usage: ~a compile [OPTIONS] SOURCE-FILE
 Compile SOURCE-FILE.
 
+  -o, --output=FILE  write compiled output to file
   -t, --to=TARGET    compile SOURCE-FILE to TARGET language;
                      Supported targets are cwl (default) and dot.
 
@@ -137,8 +142,15 @@ Compile SOURCE-FILE.
                               program)
                       (current-error-port))
              (exit (assq 'help args)))
-           (ccwl-compile (assq-ref args 'source-file)
-                         (assq-ref args 'to))))
+           (if (assq-ref args 'output-file)
+               (call-with-output-file (assq-ref args 'output-file)
+                 (cut ccwl-compile
+                      (assq-ref args 'source-file)
+                      (assq-ref args 'to)
+                      <>))
+               (ccwl-compile (assq-ref args 'source-file)
+                             (assq-ref args 'to)
+                             (current-output-port)))))
         ((program args ...)
          (let ((args (args-fold args
                                 (list %help-option)