From d36a06eca4425853616e6ea53dd8b2a3cf477124 Mon Sep 17 00:00:00 2001 From: Francois-Rene Rideau <tunes@google.com> Date: Mon, 11 Aug 2014 12:20:59 -0400 Subject: [PATCH] 2.0.2: further refine and document ON-ERROR behavior: return what it returns when CALL-FUNCTION'ed with the condition, except for NIL (continue) and T (signal error). --- README | 7 ++++--- inferior-shell.asd | 2 +- run.lisp | 22 +++++++++++----------- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/README b/README index b85a3b5..dd242e5 100644 --- a/README +++ b/README @@ -96,9 +96,10 @@ RUN CMD &KEY ON-ERROR TIME SHOW HOST OUTPUT a PROCESS-SPEC object already parsed, or a string to be passed to a Unix shell. ON-ERROR specifies behavior in case the command doesn't successfully exit - with exit code 0, as per FARE-UTILS's ERROR-BEHAVIOR provided with - (if a function, invoke it, if a string, issue an error with it, - otherwise return it as is). + with exit code 0. NIL means continue and return the error code; + T (default) means signal the error (same as :ON-ERROR 'SIGNAL); + any other value is called as by UIOP:CALL-FUNCTION with the condition as argument, + and if it returns, its return values are returned by RUN. TIME is a boolean which if true causes the execution to be timed as per TIME. SHOW is a boolean which if true causes a message to be sent to the *TRACE-OUTPUT* before execution. diff --git a/inferior-shell.asd b/inferior-shell.asd index 1672d44..09b5348 100644 --- a/inferior-shell.asd +++ b/inferior-shell.asd @@ -2,7 +2,7 @@ (defsystem "inferior-shell" :description "spawn local or remote processes and shell pipes" - :version "2.0.1" + :version "2.0.2" :defsystem-depends-on (:asdf #-asdf3 "uiop") :depends-on ((:version #+asdf3 "asdf" #-asdf3 "uiop" "3.0.3") ; input and error-output redirection #+sbcl "sb-posix" diff --git a/run.lisp b/run.lisp index e851060..3019666 100644 --- a/run.lisp +++ b/run.lisp @@ -52,19 +52,19 @@ (apply 'run-process-spec (funcall host spec) :host nil keys)))) (defun run/nil (cmd &rest keys - &key time show host - (on-error 'signal) + &key time show host (on-error t) &allow-other-keys) "run command CMD" - (labels ((process-time () - (if time (time (process-command)) (process-command))) - (process-command () - (handler-bind - ((subprocess-error #'(lambda (c) (call-function on-error c)))) - (apply 'run-process-spec cmd :ignore-error-status nil :host host keys)))) - (when show - (format *trace-output* "; ~A~%" (print-process-spec cmd))) - (process-time))) + (when (eq on-error t) (setf on-error 'signal)) + (when show + (format *trace-output* "; ~A~%" (print-process-spec cmd))) + (flet ((run-it () + (handler-bind + ((subprocess-error #'(lambda (c) + (if on-error (return-from run-it (call-function on-error c)) + (continue c))))) + (apply 'run-process-spec cmd :ignore-error-status nil :host host keys)))) + (if time (time (run-it)) (run-it)))) (defun run (cmd &rest keys &key on-error time show host (output t op) (error-output t eop) &allow-other-keys) -- GitLab