Some refactoring, and implement stat

Add convenience functions run and must to the context module, and remove
the similar functions from connection.

In the connection module, rename %run to connection-run now that that
function has moved to context.
This commit is contained in:
Ray Miller 2025-01-08 18:27:46 +00:00
parent 3153469a2c
commit 93820dc307
Signed by: ray
GPG key ID: 043F786C4CD681B8
5 changed files with 78 additions and 57 deletions

View file

@ -2,6 +2,8 @@
#:use-module (srfi srfi-1)
#:use-module (srfi srfi-9)
#:use-module (srfi srfi-26)
#:use-module (srfi srfi-71)
#:use-module (ordo connection)
#:export (make-context
context?
context-connection
@ -12,10 +14,12 @@
context-triggered?
register-context-var!
context-ref
bind-context-vars))
bind-context-vars
run
must))
(define-record-type <context>
(make-context connection vars scratch-dir)
(make-context connection vars)
context?
(connection context-connection)
(scratch-dir context-scratch-dir set-context-scratch-dir!)
@ -45,3 +49,14 @@
(lambda (ctx)
(let ((var-name (context-ref ctx (quote var-name))) ...)
(proc ctx))))))
(define* (run ctx prog args #:key (env #f) (pwd #f))
(connection-run (context-connection ctx) pwd env prog args))
(define* (must ctx prog args #:key (env #f) (pwd #f) (error-msg #f))
(let ((out rc (run ctx prog args #:env env #:pwd pwd)))
(if (zero? rc)
out
(error (if error-msg
(format #f "~a: ~a" error-msg out)
(format #f "~a error: ~a" prog out))))))