frontend.lisp: Add hooks for extensions to add new command-line options.
authorMark Wooding <mdw@distorted.org.uk>
Sun, 4 Aug 2019 18:04:10 +0000 (19:04 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Sun, 4 Aug 2019 18:11:58 +0000 (19:11 +0100)
It seems rather pointless to document the option parser and then fail to
provide any way for extensions to make use of it.

Not that I've actually documented it yet...

doc/SYMBOLS
doc/misc.tex
src/frontend.lisp

index 40aa3f5..26d1a70 100644 (file)
@@ -1611,6 +1611,7 @@ vtmsgs-subclass
 Package `sod-frontend'
 
 frontend.lisp
+  augment-options                               function
   main                                          function
 
 Classes:
index b1ade39..ec0fe59 100644 (file)
@@ -862,7 +862,7 @@ The following definitions are useful when working with conditions.
 %%%--------------------------------------------------------------------------
 \section{Option parser} \label{sec:misc.optparse}
 
-These symbols are defined in the @|optparse| package.
+Most of these symbols are defined in the @|optparse| package.
 
 \begin{describe}{fun}{exit \&optional (@<code> 0) \&key :abrupt}
 \end{describe}
@@ -1066,6 +1066,9 @@ These symbols are defined in the @|optparse| package.
           @<form>^*) @}^*}
 \end{describe}
 
+\begin{describe}{fun}{augment-options @<options-list>}
+\end{describe}
+
 %%%--------------------------------------------------------------------------
 \section{Property sets} \label{sec:misc.pset}
 
index 06311a3..2d20fbc 100644 (file)
 (defun update-usage ()
   (setf *usage* (simple-usage *options* "SOURCES...")))
 
+(export 'augment-options)
+(defun augment-options (options)
+  "Add OPTIONS to the program's options list."
+  (asetf *options* (append it options))
+  (setf (op-options *option-parser*) *options*)
+  (update-usage))
+
+(use-package "SOD-FRONTEND" "SOD-USER")
+
 (export 'main)
 (defun main ()
 
                (#\d "directory" (:arg "DIR")
                     ("Write output files to DIR.")
                     (dirpath output-path))
+               (#\e "eval" (:arg "LISP")
+                    ("Evaluate raw Lisp code.")
+                    (lambda (lisp)
+                      (handler-case
+                          (let ((*package* (find-package "SOD-USER")))
+                            (eval (read-from-string lisp)))
+                        (error (error)
+                          (option-parse-error "~A" error)))))
+               (#\l "load" (:arg "FILE")
+                    ("Load a file of Lisp code.")
+                    (lambda (file)
+                      (let ((file (merge-pathnames file
+                                                   (make-pathname
+                                                    :type "LISP"
+                                                    :case :common))))
+                        (handler-case
+                            (let ((*package* (find-package "SOD-USER")))
+                              (find-file *default-pathname-defaults* file
+                                         "Lisp file"
+                                         (lambda (path true)
+                                           (declare (ignore path))
+                                           (load true
+                                                 :verbose nil
+                                                 :print nil))))
+                          (error (error)
+                            (option-parse-error "~A" error))))))
                (#\p "stdout"
                     ("Write output files to standard output.")
                     (set stdoutp))