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.
This commit is contained in:
parent
26bc4ea150
commit
d53e08767d
1 changed files with 4 additions and 0 deletions
|
@ -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 ""))))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue