From 2c49e526105cd04d4b76bc204929ee8b8a9f6c6b Mon Sep 17 00:00:00 2001 From: Colin Okay Date: Fri, 18 Feb 2022 21:02:06 -0600 Subject: adding adding --- build-app.lisp | 34 ++++++++++++++++++++++------------ src/lib.lisp | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 12 deletions(-) diff --git a/build-app.lisp b/build-app.lisp index c2f79ba..155f8e9 100644 --- a/build-app.lisp +++ b/build-app.lisp @@ -49,23 +49,24 @@ my1337pw.") (flag :long-name "help" :description "Print this help menu.") (enum :long-name "help-topic" - :enum '(:admin :wiki :invites) + :enum '(:contributor :adding :invites) :argument-name "TOPIC" - :description "Print help for a topic. Topics are: wiki, admin, invites")) - (group (:header "Wiki" :hidden t) - (text :contents "This section documents options used to add and edit oneliners in the wiki.") - (flag :long-name "add-interactive" - :description "Interactively add a new oneliner") - (flag :long-name "update-interactive" + :description "Print help for a topic. Topics are: adding, contributor, invites")) + (group (:header "Adding" :hidden t) + (flag :long-name "add" + :description "Intaractively add a oneliner and update the wiki.") + (flag :long-name "update" :description "Interactively edit a oneliner and update the wiki.")) - (group (:header "Admin" :hidden t) + (group (:header "Contributor" :hidden t) (flag :long-name "login" :description "Attempt to login to your contributor account. ARGS are interpreted as USERNAME PASSWORD. Success will return ab API token, writing it automatically into your config file.") + (flag :long-name "revoke" + :description "Revoke your own access token.")) + (group (:header "Invites" :hidden t) (flag :long-name "invite" :description "Request an invite token to send to a friend.") (flag :long-name "redeem" - :description "Redeem an invite token. See also --help-topic=invites")) - (group (:header "Invites" :hidden t) + :description "Redeem an invite token.") (text :contents +invite-help-text+))) @@ -96,19 +97,28 @@ than the users." (handler-case (let ((arguments (remainder))) (cond + ((getopt :long-name "redeem") (destructuring-bind (token name pass) arguments (cli::redeem-invite token name pass))) + ((getopt :long-name "login") (destructuring-bind (user pass) arguments (cli::login user pass))) + ((getopt :long-name "invite") (cli::request-invite-code)) + + ((getopt :long-name "add") + (cli::add-new)) + (arguments ;; when the first argument is a number, try run a oneliner (a:when-let (hist-number (parse-integer (first arguments) :junk-allowed t)) - (format t "TBD: Going to run command ~a with arguments ~a~%" - hist-number (rest arguments)) + (if (getopt :long-name "flag") + (format t "TBD: going to flag a command~%") ;(cli::flag-item hist-number) + (format t "TBD: Going to run command ~a with arguments ~a~%" + hist-number (rest arguments))) (uiop:quit)) ;; otherwise search for oneliners (cli::search-for-oneliners arguments diff --git a/src/lib.lisp b/src/lib.lisp index 0ae2b8b..ec65d13 100644 --- a/src/lib.lisp +++ b/src/lib.lisp @@ -63,8 +63,55 @@ (when (uiop:file-exists-p (last-search-file)) (nth n (uiop:read-file-form (last-search-file))))) +(defun command-on-system (cmd) + ) + +(defun tags-from-oneliner (oneliner) + (loop for cmd? in (ppcre:split " +" oneliner) + when (command-on-system cmd?) + collect cmd?)) + +(defun prompt (prompt &key (out-stream *standard-output*) (in-stream *standard-input*)) + (princ prompt out-stream) + (read-line in-stream)) + ;;; API REQUEST FUNCTIONS +;; (defun flag-item (item-number) +;; (ensure-config) +;; (api:request-with +;; (:host (host)) +;; (a:if-let ((token (api-token)) +;; (oneliner (history item-number))) +;; (api:patch--flag-oneliner (getf oneliner :id) :token token)))) + +(defun add-new-oneliner () + (ensure-config) + (assert (api-token) () "Cannot add a oneliner without an api token.") + (let* ((oneliner + (prompt "Oneliner: ")) + (init-tags + (tags-from-oneliner oneliner)) + (brief + (prompt "Brief Description: ")) + (tags + (when (y-or-n-p "Add tags in addition to: ~{~a ~}?" init-tags) + (ppcre:split " +" (prompt "(e.g. foo bar goo): ")))) + (explaination + (when (y-or-n-p "Provide an explaination?") + (prompt "Go head: ")))) + (format t "Adding a new oneliner.~%") + + ;; (api:request-with + ;; (:host (host) + ;; :body (jonathan:to-json + ;; (list :oneliners oneliner + ;; :brief brief + ;; :tags ))) + ;; (api:post--add-oneliner :token (api-token))) + + (format t "Added~%"))) + (defun request-invite-code () (ensure-config) (api:request-with -- cgit v1.2.3