From 07183b5bbb4d2e65514e3ec3e7cdf7e421f97749 Mon Sep 17 00:00:00 2001 From: Colin Okay Date: Sun, 13 Mar 2022 11:57:06 -0500 Subject: added intial drafting code to new --- lib/client.lisp | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) (limited to 'lib/client.lisp') diff --git a/lib/client.lisp b/lib/client.lisp index fe29932..8d40fd5 100644 --- a/lib/client.lisp +++ b/lib/client.lisp @@ -131,8 +131,18 @@ running the body. If such a oneliner can be found." (prompt "Name (leave blank for none): " :expect 'valid-oneliner-name-p :retry-text "Must begin with a letter contain only letters, numbers, - and _."))) + + (draft-name + (unless (y-or-n-p "Upload immediately instead of keeping a draft?") + (if (plusp (length name)) + name + (prompt "No name was provided, name this draft: " + :expect 'valid-oneliner-name-p + :retry-text "Must begin with a letter contain only letters, numbers, - and _.")))) + (init-tags (parse-oneliner-tags oneliner-string)) + (brief (prompt "Brief Description: " :expect 'valid-brief-description-p @@ -153,17 +163,31 @@ running the body. If such a oneliner can be found." (when (y-or-n-p "Provide an explanation?") (string-from-editor (format nil "~a~%~%" oneliner-string))))) - (api:request-with - (:body (jonathan:to-json - (list :oneliner oneliner-string - :name (if (plusp (length name)) name :null) + (if draft-name + ;; if this is a draft, save it to disk. + (progn + (put-draft draft-name + (make-oneliner + :oneliner oneliner-string + :name name :tags tags :brief brief :explanation explanation :runstyle runstyle)) - :content-type "application/json") - (api:post--oneliner :token (api-token)) ;TODO: update api to return the instance created. - (format t "Added~%")))) + (format t "Saved draft ~a~%" draft-name)) + ;; otherwise, format the oneliner as json and make a request + ;; to create a new oneliner in the wiki + (api:request-with + (:body (jonathan:to-json + (list :oneliner oneliner-string + :name (if (plusp (length name)) name :null) + :tags tags + :brief brief + :explanation explanation + :runstyle runstyle)) + :content-type "application/json") + (api:post--oneliner :token (api-token)) ;TODO: update api to return the instance created. + (format t "Added Oneliner~%"))))) ;;; EDITING ONELINERS -- cgit v1.2.3