Skip to content

Commit

Permalink
Improve command validation
Browse files Browse the repository at this point in the history
  • Loading branch information
tralph3 committed Apr 29, 2024
1 parent 4db5956 commit 0143472
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
2 changes: 1 addition & 1 deletion conner-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@

(ert-deftest conner-test-update-command ()
(with-temp-env
(conner-add-command conner-root-dir '(:name "Tpyo in nmae" :command "tpyo" :type "comple"))
(conner-add-command conner-root-dir '(:name "Tpyo in nmae" :command "tpyo" :type "compile"))
(conner-update-command conner-root-dir "Tpyo in nmae" '(:name "Typo in name" :command "typst" :type "compile"))
(should (equal (get-conner-contents) '((:name "Typo in name" :command "typst" :type "compile"))))))

Expand Down
29 changes: 20 additions & 9 deletions conner.el
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,26 @@ type with an associated function in `conner-command-types-alist'."

(defun conner--is-valid-command-plist (plist)
"Return t if PLIST is a valid Conner command plist."
(and (plistp plist)
(stringp (plist-get plist :name))
(stringp (plist-get plist :command))
(or (stringp (plist-get plist :type))
(not (plist-get plist :type)))
(or (stringp (plist-get plist :workdir))
(not (plist-get plist :workdir)))
(or (listp (plist-get plist :environment))
(not (plist-get plist :environment)))))
(let ((command-types (mapcar #'car conner-command-types-alist)))
(when (not (plistp plist))
(error "Not a plist"))
(when (not (stringp (plist-get plist :name)))
(error "Name is not a string"))
(when (not (stringp (plist-get plist :command)))
(error "Command is not a string"))
(when (not (or (stringp (plist-get plist :type))
(not (plist-get plist :type))))
(error "Type is not a string"))
(when (not (member (plist-get plist :type) command-types))
(error "Unknown command type"))
(when (not (or (stringp (plist-get plist :workdir))
(not (plist-get plist :workdir))))
(error "Workdir is not a string"))
(when (not (or (listp (plist-get plist :environment))
(not (plist-get plist :environment))))
(error "Environment is not a list"))
t))


(defun conner--pp-plist (plist)
"Pretty print PLIST using line breaks after every value."
Expand Down

0 comments on commit 0143472

Please sign in to comment.