a08b75bd86ad

Add a UI
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Tue, 18 Dec 2018 21:30:00 -0500
parents 37133d1e538a
children 6385b2a6b82a
branches/tags (none)
files cacl.asd src/base.lisp

Changes

--- a/cacl.asd	Wed Nov 14 18:42:31 2018 -0500
+++ b/cacl.asd	Tue Dec 18 21:30:00 2018 -0500
@@ -5,7 +5,8 @@
   :license "MIT/X11"
   :version "0.0.1"
 
-  :depends-on (:losh
+  :depends-on (:adopt
+               :losh
                :drakma
                :flexi-streams
                :iterate
--- a/src/base.lisp	Wed Nov 14 18:42:31 2018 -0500
+++ b/src/base.lisp	Tue Dec 18 21:30:00 2018 -0500
@@ -398,8 +398,64 @@
                (handle-all-input))))
   (values))
 
+
+;;;; Command Line -------------------------------------------------------------
+(adopt:define-interface *ui*
+  "[OPTIONS] [VALUES...]"
+  (format nil "CACL is a TUI RPN calculator written (and configurable) in Common Lisp.~@
+    ~@
+    Documentation about the command-line options to the CACL binary follows.  ~
+    For information about how to use CACL itself type help when running in interactive mode.")
+
+  ((help) "display help and exit"
+   :long "help"
+   :short #\h
+   :reduce (constantly t))
+
+  ((rcfile) "path to the custom initialization file (default ~/.caclrc)"
+   :long "rcfile"
+   :parameter "PATH"
+   :initial-value "~/.caclrc"
+   :reduce #'adopt:newest)
+
+  ((rcfile no-rcfile) "disable loading of any rcfile"
+   :long "no-rcfile"
+   :reduce (constantly nil))
+
+  ((interactive mode) "run in interactive mode (the default)"
+   :long "interactive"
+   :short #\i
+   :initial-value 'interactive
+   :reduce (constantly 'interactive))
+
+  ((batch mode) "run in batch processing mode"
+   :long "batch"
+   :short #\b
+   :reduce (constantly 'batch))
+
+  ((inform) "print informational message at startup (the default)"
+   :long "inform"
+   :initial-value t
+   :reduce (constantly t))
+
+  ((no-inform inform) "suppress printing of informational message at startup"
+   :long "no-inform"
+   :reduce (constantly nil)))
+
+
 (defun toplevel ()
   ;; ccl clobbers the pprint dispatch table when dumping an image, no idea why
   (set-pprint-dispatch 'hash-table 'losh:pretty-print-hash-table)
-  (print-version)
-  (run))
+  (multiple-value-bind (arguments options) (adopt:parse-options *ui*)
+    (when (gethash 'help options)
+      (adopt:print-usage *ui*)
+      (sb-ext:exit :code 0))
+    (when (gethash 'inform options)
+      (print-version))
+    (when-let ((rc (gethash 'rcfile options)))
+      (load rc :if-does-not-exist nil))
+    (when arguments
+      (cerror "Ignore them" "Unrecognized command-line arguments: ~S" arguments))
+    (run)))
+
+