diff options
author | Colin Okay <colin@cicadas.surf> | 2022-08-05 08:58:35 -0500 |
---|---|---|
committer | Colin Okay <colin@cicadas.surf> | 2022-08-05 08:58:35 -0500 |
commit | f116178dcf8b450c76400e2a0fbd2991f2c227b4 (patch) | |
tree | 67fcc6a6e7035eb0b1929e495bceca2dc4fa564b /lib/client.lisp | |
parent | 5c590a614544c977964692e41b0e5c19043b142c (diff) |
[wip] [refactor] [add] subcommands.
Diffstat (limited to 'lib/client.lisp')
-rw-r--r-- | lib/client.lisp | 92 |
1 files changed, 34 insertions, 58 deletions
diff --git a/lib/client.lisp b/lib/client.lisp index b39e0ac..e3f304e 100644 --- a/lib/client.lisp +++ b/lib/client.lisp @@ -125,7 +125,7 @@ running the body. If such a oneliner can be found." (format t "Attempting to run:~%") (princ oneliner) (princ #\newline)) - ;; substitute positional args + (when (or (not confirm) (y-or-n-p "Proceed?")) (handle-run-oneliner oneliner (or force-clip (equalp runstyle "manual"))))))) @@ -141,11 +141,7 @@ running the body. If such a oneliner can be found." (defun add-new-oneliner () (api-token) ;; fails with error if not set. ;; read each field required to make a onelienr in from a prompt. - (let* ((oneliner-string - (prompt "Oneliner: " - :expect 'valid-oneliner-string-p - :retry-text "Oneliners must contain at least one command: ")) - (name + (let* ((name (string-trim '(#\space #\newline #\tab #\linefeed) (prompt "Name (leave blank for none): " @@ -153,13 +149,16 @@ running the body. If such a oneliner can be found." :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 _.")))) + (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 _."))) + (oneliner-string + (prompt "Oneliner: " + :expect 'valid-oneliner-string-p + :retry-text "Oneliners must contain at least one command: ")) (init-tags (parse-oneliner-tags oneliner-string)) @@ -191,32 +190,16 @@ running the body. If such a oneliner can be found." :brief brief :explanation explanation :runstyle runstyle))) - (if draft-name - ;; if this is a draft, save it to disk. - (progn - (put-draft draft-name local) - (format t "Saved draft ~a~%Do `ol --draft run ~a` to test~%" - draft-name - draft-name)) - ;; otherwise, format the oneliner as json and make a request - ;; to create a new oneliner in the wiki - (api:request-with - (:body (oneliner-to-json-body local) - :content-type "application/json") - (api:post--oneliner :token (api-token)) ;TODO: update api to return the instance created. - (format t "Added Oneliner~%")))))) + (progn + (put-draft draft-name local) + (format t "Saved draft ~a~%" draft-name))))) ;;; EDITING ONELINERS (defun edit-item (ident &optional draftp) - (api-token) ;; fails with error if not set. + ;;(unless draftp (api-token)) ;; fails with error if not set. (let ((ol (if draftp (fetch-draft ident) (the-oneliner ident)))) - (let* ((oneliner-string - (prompt "Oneliner: " - :expect 'valid-oneliner-string-p - :retry-text "Oneliners must contain at least one command: " - :prefill (oneliner-oneliner ol))) - (name + (let* ((name (string-trim '(#\space #\newline #\tab #\linefeed) (prompt "Name (leave blank for none): " @@ -225,12 +208,16 @@ running the body. If such a oneliner can be found." :prefill (or (oneliner-name ol) "")))) (draft-name - (unless (y-or-n-p "Upload edits 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 _.")))) + (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 _."))) + (oneliner-string + (prompt "Oneliner: " + :expect 'valid-oneliner-string-p + :retry-text "Oneliners must contain at least one command: " + :prefill (oneliner-oneliner ol))) (brief (prompt "Brief Description: " :expect 'valid-brief-description-p @@ -271,31 +258,20 @@ running the body. If such a oneliner can be found." :brief brief :explanation explanation :runstyle runstyle))) - (if draft-name - (progn - (put-draft draft-name local) - (format t "Saved draft ~a~%Do `ol --draft run ~a` to test~%" - draft-name - draft-name)) - (api:request-with - (:body (oneliner-to-json-body local) - :content-type "application/json") - (let ((updated - (jonathan:parse - (api:patch--oneliner-entry-edit (oneliner-id ol) :token (api-token))))) - (merge-oneliners (list updated))) - - (format t "Edits accepted~%"))))))) + (progn + (put-draft draft-name local) + (format t "Saved draft ~a~%" draft-name)))))) -;;TODO: need to sync cache here. (defun publish-draft (name) (when-draft (ol name) (api:request-with (:body (oneliner-to-json-body ol) :content-type "application/json") - (if (oneliner-id ol) - (api:patch--oneliner-entry-edit (oneliner-id ol) :token (api-token)) - (api:post--oneliner :token (api-token))) + (let ((updated + (if (oneliner-id ol) + (api:patch--oneliner-entry-edit (oneliner-id ol) :token (api-token)) + (api:post--oneliner :token (api-token))))) + (merge-oneliners (list updated))) ;; if that worked, no http error occured, so this next part will run (drop-draft name) (format t "Draft ~a published and removed from drafts.~%" name)))) |