Refactor to use a core namespace with global vars
This commit is contained in:
parent
a65415f846
commit
04a75984cb
3 changed files with 222 additions and 46 deletions
|
@ -19,7 +19,11 @@
|
|||
connection-run
|
||||
connection-call-with-input-file
|
||||
connection-call-with-output-file
|
||||
call-with-connection))
|
||||
call-with-connection
|
||||
must
|
||||
run
|
||||
must1
|
||||
run1))
|
||||
|
||||
(define-class <connection> ()
|
||||
(sudo #:getter sudo? #:init-keyword #:sudo))
|
||||
|
@ -74,12 +78,6 @@
|
|||
(loop (read-line port) (cons line result))))
|
||||
(loop (read-line port) '()))
|
||||
|
||||
(define (kw-arg kw kwargs)
|
||||
(cond
|
||||
((null? (kwargs)) #f)
|
||||
((equal? (car kwargs) kw) (cadr kwargs))
|
||||
(else (kw-arg kw (cddr kwargs)))))
|
||||
|
||||
(define-method (build-command (c <connection>) pwd env prog args)
|
||||
(let ((cmd (list (if (sudo? c) "sudo" "env"))))
|
||||
(chain-when cmd
|
||||
|
@ -123,3 +121,34 @@
|
|||
(lambda () (init-connection! c))
|
||||
(lambda () (proc c))
|
||||
(lambda () (close-connection! c))))
|
||||
|
||||
(define (keyword-arg kw args)
|
||||
(cond
|
||||
((< (length args) 2) #f)
|
||||
((equal? (first args) kw) (second args))
|
||||
(else (keyword-arg kw (cddr args)))))
|
||||
|
||||
(define (run conn prog . args)
|
||||
(let* ((args kwargs (break keyword? args))
|
||||
(pwd (keyword-arg #:pwd kwargs))
|
||||
(env (keyword-arg #:env kwargs)))
|
||||
(connection-run conn pwd env prog args)))
|
||||
|
||||
(define (run1 . args)
|
||||
(let ((out rc (apply run args)))
|
||||
(values (first out) rc)))
|
||||
|
||||
(define (must conn prog . args)
|
||||
(let* ((args kwargs (break keyword? args))
|
||||
(pwd (keyword-arg #:pwd kwargs))
|
||||
(env (keyword-arg #:env kwargs))
|
||||
(error-msg (keyword-arg #:error-msg kwargs))
|
||||
(out rc (connection-run conn pwd env prog args)))
|
||||
(if (zero? rc)
|
||||
out
|
||||
(error (if error-msg
|
||||
(format #f "~a: ~a" error-msg out)
|
||||
(format #f "~a error: ~a" prog out))))))
|
||||
|
||||
(define (must1 . args)
|
||||
(first (apply must args)))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue