da80130c3bbf

Adopt adopt
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Fri, 21 Dec 2018 22:12:57 -0500
parents 0a3160c5895c
children f592e6093609
branches/tags (none)
files Makefile brows.asd src/build.lisp src/main.lisp

Changes

--- a/Makefile	Sat May 26 14:38:30 2018 -0400
+++ b/Makefile	Fri Dec 21 22:12:57 2018 -0500
@@ -1,5 +1,7 @@
 .PHONY: vendor clean binary-sbcl binary-ccl binary
 
+all: binary
+
 # Vendor ----------------------------------------------------------------------
 vendor/quickutils.lisp: vendor/make-quickutils.lisp
 	cd vendor && sbcl --noinform --load make-quickutils.lisp  --eval '(quit)'
@@ -24,5 +26,5 @@
 
 binary: binary-sbcl
 
-bin/brows: $(lisps) $(assets) Makefile
+bin/brows: $(lisps) Makefile
 	make binary-sbcl
--- a/brows.asd	Sat May 26 14:38:30 2018 -0400
+++ b/brows.asd	Fri Dec 21 22:12:57 2018 -0500
@@ -8,6 +8,7 @@
 
   :depends-on (
 
+               :adopt
                :boots
                :cl-ppcre
                :deploy
--- a/src/build.lisp	Sat May 26 14:38:30 2018 -0400
+++ b/src/build.lisp	Fri Dec 21 22:12:57 2018 -0500
@@ -1,4 +1,7 @@
-(ql:quickload :brows)
+(ql:quickload :brows :silent t)
+
+(with-open-file (stream "bin/brows.1" :direction :output :if-exists :supersede)
+  (adopt:print-manual brows::*ui* :stream stream))
 
 (setf deploy:*status-output* nil)
 
--- a/src/main.lisp	Sat May 26 14:38:30 2018 -0400
+++ b/src/main.lisp	Fri Dec 21 22:12:57 2018 -0500
@@ -117,14 +117,39 @@
         ((#\j :down) (incf-pos 1))
         (t nil)))))
 
-(defmacro catch-and-spew-errors (&body body)
-  `(handler-case (progn ,@body)
-     (t (c) (format t "Error: ~A" c))))
+(defun run ()
+  (boots:with-boots (:fresh-tty t)
+    (boots:with-layer ()
+        (boots:canvas () #'draw)
+      (init)
+      (main))))
+
+
+;;;; CLI ----------------------------------------------------------------------
+(adopt:define-string *documentation*
+  "Brows is a utility for finding links in a chunk of text and presenting a ~
+  nice text-based UI for opening them.  It's written (and customizable) in ~
+  Common Lisp.")
+
+(adopt:define-interface *ui*
+    (:name "brows"
+     :summary "Find links and present a menu for opening them in a browser."
+     :usage "[OPTIONS]"
+     :documentation *documentation*
+     :examples '(("Present a menu for opening some links:" .
+                  "curl http://stevelosh.com/ | brows")))
+  (help
+    :documentation "display help and exit"
+    :long "help"
+    :short #\h
+    :reduce (constantly t)))
 
 (defun toplevel ()
-  (catch-and-spew-errors
-    (boots:with-boots (:fresh-tty t)
-      (boots:with-layer ()
-          (boots:canvas () #'draw)
-        (init)
-        (main)))))
+  (handler-case
+      (multiple-value-bind (arguments options) (adopt:parse-options *ui*)
+        (when (gethash 'help options)
+          (adopt:print-usage-and-exit *ui*))
+        (unless (null arguments)
+          (error "Unrecognized command line arguments: ~S" arguments))
+        (run))
+    (error (c) (adopt:print-error-and-exit c))))