aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2022-05-08 18:57:29 +0200
committerTeddy Wing2022-05-08 18:57:29 +0200
commit9273bf5776bee60aa12a386eba44d02577a1a810 (patch)
treefca74bb9a2958303552b5fb0ae0f6b4ad9e07628
parentca75a8f0f3860f0ac64eaf7fdeaec422912fcd99 (diff)
downloadwajir-9273bf5776bee60aa12a386eba44d02577a1a810.tar.bz2
option.lisp: Require `--login`, `--token`, `--endpoint` options
It took a few tries to get this working, but it correctly checks for these missing arguments now and prints a warning indicating which ones are missing.
-rw-r--r--src/option.lisp78
1 files changed, 78 insertions, 0 deletions
diff --git a/src/option.lisp b/src/option.lisp
index 4d1ce19..32fe6d4 100644
--- a/src/option.lisp
+++ b/src/option.lisp
@@ -82,6 +82,84 @@ with code `exit-code`."
(opts:exit sysexits:+ok+))
+ ;; Check required arguments
+ ; (dolist (opt '(:login :token :endpoint))
+ ; ())
+ ; (when (null (getf options :login))
+ ; (format *error-output* "~S"
+ ; (loop
+ ; for opt in '(:login :token :endpoint)
+ ; with '(opt (null (getf options opt)))
+ ; collect result))
+ ; (when (null (getf options :login))
+ ; (let ((required-opts
+ ; (mapcar
+ ; #'(lambda (opt) `(,opt ,(not (null (getf options opt)))))
+ ; '(:login :token :endpoint))))
+ ; (format *error-output* "opts: ~S" required-opts)
+ ; (opts:exit sysexits:+usage+)))
+ ; (when (or (null (getf options :login))
+ ; (null (getf options :token))
+ ; (null (getf options :endpoint)))
+ ; (format *error-output* "error: missing required options: ~A"))
+
+ ; (let* ((required-opts '(:login :token :endpoint))
+ ; (opts-missing-p (mapcar
+ ; #'(lambda (opt) (null (getf options opt)))
+ ; required-opts)))
+ ; ; (opts-missing-p (mapcar
+ ; ; #'(lambda (opt)
+ ; ; (cons (null (getf options opt))
+ ; ; opt))
+ ; ; required-opts))
+ ; ; (missing-opts (mapcar
+ ; ; #'second
+ ; ; (remove-if-not
+ ; ; #'(lambda (missing-and-opt) (first missing-and-opt))
+ ; ; opts-missing-p))))
+ ;
+ ; (format *error-output* "miss: ~S~%" opts-missing-p)
+ ; (when (or (values opts-missing-p))
+ ; (let* ((opt-and-presence
+ ; (mapcar #'cons opts-missing-p required-opts))
+ ; (missing-opts
+ ; (remove-if
+ ; #'(lambda (presence-pair) (null (first presence-pair)))
+ ; opt-and-presence)))
+ ;
+ ; (format *error-output* "opts: ~S~%" missing-opts)
+ ; (opts:exit sysexits:+usage+))))
+ ;
+ ; ; (format *error-output* "v2: ~S~%" missing-opts))
+
+ (let* ((required-opts '(:login :token :endpoint))
+
+ ;; (nil nil t)
+ ; (opts-missing-p (mapcar
+ ; #'(lambda (opt) (null (getf options opt)))
+ ; required-opts))
+
+ ;; ((t . :login) (t . :token) (nil . :endpoint))
+ (opts-missing-p (mapcar
+ #'(lambda (opt)
+ (cons (null (getf options opt))
+ opt))
+ required-opts))
+
+ ;; (:endpoint)
+ (missing-opts (mapcar
+ #'cdr
+ (remove-if-not
+ #'(lambda (missing-and-opt) (first missing-and-opt))
+ opts-missing-p))))
+
+ (format
+ *error-output*
+ "error: missing required options: ~{`~(--~A~)'~^, ~}~%"
+ missing-opts)
+
+ (opts:exit sysexits:+usage+))
+
;; If `sendmail` is given, `email-to` must be defined.
(when (not (null (getf options :sendmail)))
(when (null (getf options :email-to))