Mercurial > core / lisp/lib/cli/clap/macs.lisp
changeset 698: |
96958d3eb5b0 |
parent: |
65102f74d1ae
|
author: |
Richard Westhaver <ellis@rwest.io> |
date: |
Fri, 04 Oct 2024 22:04:59 -0400 |
permissions: |
-rw-r--r-- |
description: |
fixes |
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) 51 (let ((*argc* (length args)) 52 (*optc* (length opts)) 57 (defmacro defopt (name &body body) 58 `(defun ,name (&optional arg) 63 ;; (defmacro gen-cli-thunk (pvars &rest thunk) 64 ;; "Generate and return a function based on THUNK suitable for the :thunk 65 ;; slot of cli objects with pandoric bindings PVARS.") 67 (defmacro make-opt-parser (kind-spec &body body) 68 "Return a KIND-opt-parser function based on KIND-SPEC which is either a 69 symbol from *cli-opt-kinds* or a list, and optional BODY which 70 is a list of handlers for the opt-val." 71 (let* ((kind (if (consp kind-spec) (car kind-spec) kind-spec)) 72 (super (when (consp kind-spec) (cadr kind-spec))) 73 (fn-name (symbolicate 'parse- kind '-opt))) 75 (let ((fn1 (unless (null super) (symbolicate "PARSE-" super "-OPT")))) 76 `(defun ,fn-name (&optional arg) 77 "Parse the cli-opt-val *ARG*." 78 (declare (ignorable arg)) 80 `((setf *arg* (print (funcall #',fn1 arg))))