X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/zone/blobdiff_plain/7e282fb5afd9b871063614a3e442d2d599757862..cc0fa47a50532786e202ee24c6518e50ba6959e2:/frontend.lisp diff --git a/frontend.lisp b/frontend.lisp index bd00ff4..46c5a36 100644 --- a/frontend.lisp +++ b/frontend.lisp @@ -13,78 +13,81 @@ ;;; it under the terms of the GNU General Public License as published by ;;; the Free Software Foundation; either version 2 of the License, or ;;; (at your option) any later version. -;;; +;;; ;;; This program is distributed in the hope that it will be useful, ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;;; GNU General Public License for more details. -;;; +;;; ;;; You should have received a copy of the GNU General Public License ;;; along with this program; if not, write to the Free Software Foundation, ;;; Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. (defpackage #:zone.frontend - (:use #:common-lisp #:mdw.optparse #:zone) + (:use #:common-lisp #:optparse #:net #:zone) (:export #:main)) (in-package #:zone.frontend) -(defconstant version "1.0.0") - (defvar opt-zones nil "Which zones to be emitted.") +(defvar opt-format :bind + "Which format to use on output.") -(defvar options nil) -(defvar usage nil) -(defun help (arg) - (declare (ignore arg)) - (show-help *program-name* version usage options) - (exit 0)) -(defun version (arg) - (declare (ignore arg)) - (format t "~A, version ~A~%" *program-name* version) - (exit 0)) -(defun do-usage (&optional (stream *standard-output*)) - (show-usage *program-name* usage stream)) -(defun usage (arg) - (declare (ignore arg)) - (do-usage) - (exit 0)) -(setf options - (options - "Help options" - (#\h "help" #'help - "Show this help message.") - (#\v "version" #'version - ("Show the `~A' program's version number." *program-name*)) - (#\u "usage" #'usage - ("Show a very brief usage summary for `~A'." *program-name*)) +(eval-when (:compile-toplevel :load-toplevel) + (defopthandler dir (var arg) () + (let ((path (probe-file arg))) + (if (and path + (not (pathname-name path))) + (setf var path) + (option-parse-error "path `~A' doesn't name a directory." arg))))) - "Output options" - (#\z "zone" (:arg "NAME") (list opt-zones) - "Write information about zone NAME."))) -(setf usage (simple-usage options "ZONEDEF...")) +(define-program + :version "1.0.0" :usage "ZONEDEF..." + :help "Generates BIND zone files from Lisp descriptions." + :options (options help-options + "Parsing options" + (#\f "feature" (:arg "KEYWORD") + (list *features* 'keyword) + "Insert KEYWORD in *features* list.") + (#\s "subnet" (:arg "NET") + (list zone:*preferred-subnets*) + "Designate NET as a preferred subnet.") + "Output options" + (#\d "directory" (:arg "DIRECTORY") + (dir *zone-output-path*) + "Write zone and serial files to DIRECTORY.") + (#\F "format" (:arg "FORMAT") + (keyword opt-format + (delete-duplicates + (loop for method in + (pcl:generic-function-methods + #'zone:zone-write) + for specs = + (pcl:method-specializers method) + if (typep (car specs) + 'pcl:eql-specializer) + collect + (pcl:eql-specializer-object + (car specs))))) + "Format to use for output.") + (#\z "zone" (:arg "NAME") (list opt-zones) + "Write information about zone NAME."))) (defun main () (with-unix-error-reporting () - (let ((seq 54) - (files nil) - (op (make-option-parser (cdr *command-line-strings*) options))) + (let ((files nil)) (unless (option-parse-try - (loop - (multiple-value-bind (opt arg) (option-parse-next op) - (declare (ignore arg)) - (unless opt - (return)))) - (setf files (option-parse-remainder op)) - (when (zerop (length files)) - (option-parse-error "no files to read"))) - (do-usage *error-output*) - (exit 1)) + (do-options () + (nil (rest) + (when (zerop (length rest)) + (option-parse-error "no files to read")) + (setf files rest)))) + (die-usage)) (dolist (f files) - (let ((*package* (make-package (format nil "zone.scratch-~A" - (incf seq)) - :use '(#:common-lisp #:zone)))) - (load f :verbose nil :print nil :if-does-not-exist :error))) - (zone-save opt-zones)))) + (let ((*package* (make-package "ZONE.SCRATCH" + :use '(#:common-lisp #:net #:zone)))) + (load f :verbose nil :print nil :if-does-not-exist :error) + (delete-package *package*))) + (zone-save opt-zones :format opt-format)))) ;;;----- That's all, folks --------------------------------------------------