Mercurial > core / lisp/lib/cli/clap/macs.lisp
changeset 643: |
f901de70a80e |
parent: |
f8b76ced5e2d
|
child: |
65102f74d1ae |
author: |
Richard Westhaver <ellis@rwest.io> |
date: |
Tue, 10 Sep 2024 21:26:30 -0400 |
permissions: |
-rw-r--r-- |
description: |
opt fixes and test updates |
1 ;;; cli/clap/macs.lisp --- Clap Macros 6 (in-package :cli/clap/macs) 8 (defmacro argp (arg &optional (args (args))) 9 "Test for presence of ARG in ARGS. Return the tail of 10 ARGS starting from the position of ARG." 11 `(member ,arg ,args :test 'equal)) 13 (defmacro make-shorty (name) 14 "Return the first char of symbol or string NAME." 15 `(character (aref (if (stringp ,name) ,name (symbol-name ,name)) 0))) 17 (defmacro with-cli-handlers (&body body) 18 "A wrapper which handles common cli errors that may occur during 22 (sb-ext:enable-debugger) 23 (sb-ext:disable-debugger)) 27 (sb-sys:interactive-interrupt () 29 (sb-ext:exit :code 130)) 33 "Skip to toplevel READ/EVAL/PRINT loop." 35 (log:debug! "CONTINUEing from pre-REPL RESTART-CASE") 38 :report "Exit SBCL (calling #'EXIT, killing the process)." 39 ;; :test (lambda (c) (declare (ignore c)) t) 40 (log:debug! "falling through to EXIT from pre-REPL RESTART-CASE") 42 (sb-impl::flush-standard-output-streams) 43 ;; reset terminal state 46 ;; TODO fix these macros 47 (defmacro defcmd (name &body body) 48 `(defun ,name (args opts) 49 (declare (ignorable args opts) 58 (defmacro defopt (name &body body) 59 `(defun ,name (&optional arg) 60 (declare (ignorable arg)) 65 ;; (defmacro gen-cli-thunk (pvars &rest thunk) 66 ;; "Generate and return a function based on THUNK suitable for the :thunk 67 ;; slot of cli objects with pandoric bindings PVARS.") 69 (defmacro make-opt-parser (kind-spec &body body) 70 "Return a KIND-opt-parser function based on KIND-SPEC which is either a 71 symbol from *cli-opt-kinds* or a list, and optional BODY which 72 is a list of handlers for the opt-val." 73 (let* ((kind (if (consp kind-spec) (car kind-spec) kind-spec)) 74 (super (when (consp kind-spec) (cadr kind-spec))) 75 (fn-name (symbolicate 'parse- kind '-opt))) 77 (let ((fn1 (unless (null super) (symbolicate "PARSE-" super "-OPT")))) 78 `(defun ,fn-name (&optional arg) 79 "Parse the cli-opt-val *ARG*." 80 (declare (ignorable arg)) 82 `((setf *arg* (print (funcall #',fn1 arg))))