Test (and bugfix) conditions

This commit is contained in:
Ray Miller 2025-01-10 17:31:11 +00:00
parent 875ce167e9
commit dba8ca3153
Signed by: ray
GPG key ID: 043F786C4CD681B8
2 changed files with 12 additions and 9 deletions

View file

@ -1,8 +1,9 @@
(define-module (ordo condition)
#:use-moudle (ordo context)
#:use-module (srfi srfi-71)
#:use-module (ordo context)
#:use-module (ordo action filesystem))
(define (cond:any preds)
(define-public (cond:any preds)
(lambda (ctx)
(let loop ((preds preds))
(if (null? preds)
@ -12,7 +13,7 @@
#t
(loop (cdr preds))))))))
(define (cond:every preds)
(define-public (cond:every preds)
(lambda (ctx)
(let loop ((preds preds))
(if (null? preds)
@ -22,17 +23,17 @@
(loop (cdr preds))
#f))))))
(define (cond:command-available? cmd-name)
(define-public (cond:command-available? cmd-name)
(lambda (ctx)
(let ((_ rc) (run "which" `(,cmd-name)))
(let ((_ rc (run "which" `(,cmd-name))))
(zero? rc))))
(define (cond:directory? path)
(define-public (cond:directory? path)
(lambda (ctx)
(let ((st ((action:stat path) ctx)))
(and st (string=? "directory" (assoc-ref st 'file-type))))))
(define (cond:regular-file? path)
(define-public (cond:regular-file? path)
(lambda (ctx)
(let ((st ((action:stat path) ctx)))
(and st (string=? "regular-file" (assoc-ref st 'file-type))))))

View file

@ -1,7 +1,8 @@
(use-modules
(ice-9 filesystem)
(ordo condition)
(ordo connection)
(ordo context )
(ordo context)
(ordo action filesystem)
(ordo play)
(ordo task)
@ -18,7 +19,8 @@
(task "Create test directory"
(bind-context-vars
(base-dir)
(action:install-dir base-dir)))
(action:install-dir base-dir))
#:condition (bind-context-vars (base-dir) (negate (cond:directory? base-dir))))
(task "Create test file from string content"
(bind-context-vars
(base-dir)