# HG changeset patch # User Steve Losh # Date 1545448377 18000 # Node ID da80130c3bbf8b9ffd5a587dbf1ebee61853e761 # Parent 0a3160c5895ca900f9b20039b3e1bec58f4b4aa8 Adopt adopt diff -r 0a3160c5895c -r da80130c3bbf Makefile --- 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 diff -r 0a3160c5895c -r da80130c3bbf brows.asd --- 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 diff -r 0a3160c5895c -r da80130c3bbf src/build.lisp --- 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) diff -r 0a3160c5895c -r da80130c3bbf src/main.lisp --- 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))))