From 26bc4ea150d485df29c9370cc299e5d91881d56d Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sun, 7 Aug 2022 17:26:07 +0200 Subject: [PATCH] feat(cli): allow multiple implicit types for options Now you can specify more than one allowed (implicit) for a CLI option: (defcli! (doom somecommand) ((foo ("--foo" (file int))))) This will test FOO to ensure it is either an existing file path or an integer. If neither is true, you'll see this helpful error: Error: -o/--file received invalid value "FOO" Validation errors: - Not an integer. - Not a valid path to an existing file. --- lisp/doom-cli-lib.el | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lisp/doom-cli-lib.el b/lisp/doom-cli-lib.el index 304586f78..06b905300 100644 --- a/lisp/doom-cli-lib.el +++ b/lisp/doom-cli-lib.el @@ -537,9 +537,9 @@ Throws `doom-cli-invalid-option-error' for illegal values." nil (cl-loop for spec in argspec if (or (and (stringp spec) (not (string-match-p "^-\\(?:-[a-zA-Z0-9]\\|[^-]$\\)" spec))) - (keywordp spec)) - collect spec - else if (symbolp spec) + (keywordp spec) + (symbolp spec) + (listp spec)) collect spec))) (defun doom-cli--make-option-generic (symbol spec &optional docs) @@ -1408,14 +1408,16 @@ formats: If a string, they are used verbatim as the argument's documentation. Use this to document more complex specifications, like \"[user@]host[:port]\". - Use reference `quotes' to highlight arguments appropriately. + Use reference `quotes' to highlight arguments appropriately. No input + validation is performed on these arguments. If a symbol, this is equivalent to (upcase (format \"`%s'\" SYMBOL)), but its arguments will also be implicitly validated against `doom-cli-option-arg-types'. A nested list indicates that an argument accepts multiple types, and are - implicitly joined into \"`ARG1'|`ARG2'|...\". + implicitly joined into \"`ARG1'|`ARG2'|...\". Input validation is performed + on symbols only. WARNING: If this option is a &flag, the option must not accept arguments. Instead, use ARGSPEC to specify a single, default value (one of `:yes' or