From d53e08767dd003c9c78f9739fcd7cf7e0ae199cb Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sun, 7 Aug 2022 17:22:56 +0200 Subject: [PATCH] feat(cli): add stdout implicit arg type CLIs can now use this for implicit validation for options that take a file path or - to signal "print to stdout", like so: (defcli! (doom command) ((outfile ("--out" (file stdout)))) (if (equal outfile "-") (print! "output") (with-temp-file outfile (insert "output")))) If OUTFILE is not an existing file path or a -, you'll see an this helpful error: Error: -o/--file received invalid value "FOO" Validation errors: - Must be a dash to signal stdout. - File does not exist. See 'doom h[elp] make codeowners' or 'doom make codeowners {-?,--help}' for documentation. --- lisp/doom-cli-lib.el | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lisp/doom-cli-lib.el b/lisp/doom-cli-lib.el index 06b905300..7d17765ba 100644 --- a/lisp/doom-cli-lib.el +++ b/lisp/doom-cli-lib.el @@ -62,6 +62,10 @@ See argument types in `doom-cli-argument-types', and `defcli!' for usage.") :read doom-path :error "File does not exist" :zshcomp "_files") + (stdout :test ,(lambda (str) (equal str "-")) + :read identity + :error "Must be a dash to signal stdout" + :zshcomp "(-)") (path :read expand-file-name :zshcomp "_files") (form :read read) (regexp :test ,(lambda (str) (always (string-match-p str ""))))