changelog shortlog graph tags branches changeset files revisions annotate raw help

Mercurial > core / lisp/lib/cli/clap/util.lisp

changeset 649: 6e5006dfe7b8
parent: 3e6a17fb5712
child: 119532882cb1
author: Richard Westhaver <ellis@rwest.io>
date: Thu, 12 Sep 2024 22:38:22 -0400
permissions: -rw-r--r--
description: clap parsing updates
1 ;;; cli/clap/util.lisp --- Clap Utilities
2 
3 ;;
4 
5 ;;; Code:
6 (in-package :cli/clap/util)
7 
8 (defun arg0 () (car sb-ext:*posix-argv*))
9 (defun args () (cdr sb-ext:*posix-argv*))
10 
11 (declaim (inline long-opt-p long-opt-has-eq-p
12  short-opt-p opt-group-p
13  opt-string-prefix-eq))
14 
15 (defun long-opt-p (str)
16  (declare (simple-string str))
17  (and (> (length str) 2)
18  (char= (aref str 0) (aref str 1) #\-)))
19 
20 (defun long-opt-has-eq-p (str)
21  "Return non-nil if STR is a long-opt which has an '=' somewhere,
22 indicating a key/val pair without whitespace."
23  (declare (simple-string str))
24  (when-let ((pos (position #\= str :test 'char=)))
25  (cons (subseq str 2 pos) (subseq str (1+ pos)))))
26 
27 (defun short-opt-p (str)
28  (declare (simple-string str))
29  (and (char= (aref str 0) #\-)
30  (> (length str) 1)
31  (not (char= (aref str 1) #\-))))
32 
33 (defun opt-group-p (str)
34  (declare (simple-string str))
35  (equalp str *cli-group-separator*))
36 
37 (defun opt-string-prefix-eq (ch str)
38  (declare (simple-string str) (character ch))
39  (char= ch (aref str 0)))
40 
41 ;; currently not in use
42 (defun gen-thunk-ll (origin args)
43  (let ((a0 (list (symbolicate '$a 0) origin)))
44  (group
45  (nconc (loop for i from 1 for a in args nconc (list (symbolicate '$a (the fixnum i)) a)) a0)
46  2)))
47 
48 (defun default-thunk (args opts)
49  (declare (ignore args opts))
50  (values))
51 
52 (defun cli-opt-kind-p (s)
53  (declare (type symbol s))
54  (find s *cli-opt-kinds* :test 'string-equal))