From d9f5bff5e02cef6d5e8338ef8005e001dab71d35 Mon Sep 17 00:00:00 2001 From: Dimitri Fontaine Date: Tue, 6 Jan 2015 01:18:54 +0100 Subject: [PATCH] Cleanup some code location. --- src/main.lisp | 40 +++++++++++++++++++++++++++++++++ src/package.lisp | 2 +- src/parsers/command-parser.lisp | 40 --------------------------------- 3 files changed, 41 insertions(+), 41 deletions(-) diff --git a/src/main.lisp b/src/main.lisp index 08e15b9..c10f0a6 100644 --- a/src/main.lisp +++ b/src/main.lisp @@ -349,6 +349,46 @@ (log-message :error "Can not find file: ~s" filename))) (format t "~&")) +(defun run-commands (source + &key + (start-logger t) + ((:summary *summary-pathname*) *summary-pathname*) + ((:log-filename *log-filename*) *log-filename*) + ((:log-min-messages *log-min-messages*) *log-min-messages*) + ((:client-min-messages *client-min-messages*) *client-min-messages*)) + "SOURCE can be a function, which is run, a list, which is compiled as CL + code then run, a pathname containing one or more commands that are parsed + then run, or a commands string that is then parsed and each command run." + + (with-monitor (:start-logger start-logger) + (let* ((funcs + (typecase source + (function (list source)) + + (list (list (compile nil source))) + + (pathname (mapcar (lambda (expr) (compile nil expr)) + (parse-commands-from-file source))) + + (t (mapcar (lambda (expr) (compile nil expr)) + (if (probe-file source) + (parse-commands-from-file source) + (parse-commands source))))))) + + ;; maybe duplicate the summary to a file + (let* ((summary-stream (when *summary-pathname* + (open *summary-pathname* + :direction :output + :if-exists :rename + :if-does-not-exist :create))) + (*report-stream* (or summary-stream *standard-output*))) + (unwind-protect + ;; run the commands + (loop for func in funcs do (funcall func)) + + ;; cleanup + (when summary-stream (close summary-stream))))))) + ;;; ;;; Main API to use from outside of pgloader. diff --git a/src/package.lisp b/src/package.lisp index 6843552..64be8ec 100644 --- a/src/package.lisp +++ b/src/package.lisp @@ -459,7 +459,7 @@ (:import-from #:pgloader.db3 #:dbf-connection) (:import-from #:pgloader.ixf #:ixf-connection) (:export #:parse-commands - #:run-commands + #:parse-commands-from-file ;; tools to enable complete CLI parsing in main.lisp #:process-relative-pathnames diff --git a/src/parsers/command-parser.lisp b/src/parsers/command-parser.lisp index 54f4d24..f66480d 100644 --- a/src/parsers/command-parser.lisp +++ b/src/parsers/command-parser.lisp @@ -132,46 +132,6 @@ ;; normal error processing happen (parse 'commands content)))))) -(defun run-commands (source - &key - (start-logger t) - ((:summary *summary-pathname*) *summary-pathname*) - ((:log-filename *log-filename*) *log-filename*) - ((:log-min-messages *log-min-messages*) *log-min-messages*) - ((:client-min-messages *client-min-messages*) *client-min-messages*)) - "SOURCE can be a function, which is run, a list, which is compiled as CL - code then run, a pathname containing one or more commands that are parsed - then run, or a commands string that is then parsed and each command run." - - (with-monitor (:start-logger start-logger) - (let* ((funcs - (typecase source - (function (list source)) - - (list (list (compile nil source))) - - (pathname (mapcar (lambda (expr) (compile nil expr)) - (parse-commands-from-file source))) - - (t (mapcar (lambda (expr) (compile nil expr)) - (if (probe-file source) - (parse-commands-from-file source) - (parse-commands source))))))) - - ;; maybe duplicate the summary to a file - (let* ((summary-stream (when *summary-pathname* - (open *summary-pathname* - :direction :output - :if-exists :rename - :if-does-not-exist :create))) - (*report-stream* (or summary-stream *standard-output*))) - (unwind-protect - ;; run the commands - (loop for func in funcs do (funcall func)) - - ;; cleanup - (when summary-stream (close summary-stream))))))) - ;;; ;;; Parse an URI without knowing before hand what kind of uri it is.