diff options
author | Colin Okay <okay@toyful.space> | 2022-03-05 17:22:59 -0600 |
---|---|---|
committer | Colin Okay <okay@toyful.space> | 2022-03-05 17:22:59 -0600 |
commit | d8376d1bd717181892e339a6ca42be83b7ffae66 (patch) | |
tree | 728a577ac1a526b2febc44526340c637a6527ccd | |
parent | ba5d58c335a69597fcd2531304eee42ef5247b1f (diff) |
--newest and --all-flagged now work with ARGUMENTS
-rw-r--r-- | build-app.lisp | 16 | ||||
-rw-r--r-- | oneliners.api-client.lisp | 168 | ||||
-rw-r--r-- | src/lib.lisp | 6 |
3 files changed, 112 insertions, 78 deletions
diff --git a/build-app.lisp b/build-app.lisp index adf8c08..b50635f 100644 --- a/build-app.lisp +++ b/build-app.lisp @@ -102,11 +102,11 @@ export EDITOR=/usr/bin/zile :description "The maximum number of results to return." :typespec 'integer) (flag :long-name "all-flagged" - :description "Return flagged oneliners.") + :description "Request that only flagged oneliners are returned. Without any ARGUMENTS, simply returns all flagged oneliners.") (flag :long-name "not-flagged" - :description "Request that no flagged oneliners are returned.") + :description "Request that no flagged oneliners are returned with the search results. Does nothing without ARGUMENTS") (flag :long-name "newest" - :description "Return newest oneliners.")) + :description "Return newest oneliners that match. Without any ARGUMENTS, simply returns the newest oneliners.")) (text :contents " ") (group (:header "EXECUTION OPTIONS") (text :contents "Several options override the default interpretation of ARGUMENTS.") @@ -238,12 +238,10 @@ than the users." ((getopt :long-name "add") (cli::add-new-oneliner)) - ((getopt :long-name "all-flagged") - (format t "WARNING: --all-flagged is likely to soon change its behavior~%.") + ((and (null arguments) (getopt :long-name "all-flagged")) (cli::all-flagged-oneliners (getopt :long-name "limit"))) - ((getopt :long-name "newest") - (format t "WARNING: --newest is likely to soon change its behavior~%") + ((and (null arguments) (getopt :long-name "newest")) (cli::newest-oneliners (getopt :long-name "limit"))) ((getopt :long-name "clear-cache") @@ -274,7 +272,9 @@ than the users." (t (cli::search-for-oneliners arguments (getopt :long-name "limit") - (getopt :long-name "not-flagged"))))) + (getopt :long-name "not-flagged") + (getopt :long-name "all-flagged") + (getopt :long-name "newest"))))) (uiop:quit)) (t (help))) diff --git a/oneliners.api-client.lisp b/oneliners.api-client.lisp index 5fc6f10..e135973 100644 --- a/oneliners.api-client.lisp +++ b/oneliners.api-client.lisp @@ -21,7 +21,8 @@ #:PUT--CONTRIBUTOR-WHO-SIGNATURE #:PUT--CONTRIBUTOR-WHO-PASSWORD #:PUT--CONTRIBUTOR-WHO-LOCKED -#:GET--CONTRIBUTOR-WHO)) +#:GET--CONTRIBUTOR-WHO +#:POST--SNAPSHOT)) (in-package :ONELINERS.API-CLIENT) @@ -70,14 +71,14 @@ COOKIES should be an instance of CL-COOKIE:COOKIE-JAR. Defaults to (dex:response-body ,http-error-var))))))) -(DEFUN GET--ONELINERS (&KEY TAGS LIMIT NOTFLAGGED) +(DEFUN GET--ONELINERS (&KEY TAGS LIMIT NOTFLAGGED NEWEST ONLYFLAGGED) "A search endpoint returning a JSON encoded array of Oneliner Entries. TAGS cannot be empty. Returns a [Search Result](#search-result) object." (LET ((LAZYBONES-CLIENT.SHARED::REQ-STRING (APPLY #'CONCATENATE 'STRING LAZYBONES-CLIENT.SHARED:*HOST* "/api" (FORMAT NIL "/oneliners") - (WHEN (OR TAGS LIMIT NOTFLAGGED) + (WHEN (OR TAGS LIMIT NOTFLAGGED NEWEST ONLYFLAGGED) (LIST "?" (IF TAGS (CONCATENATE 'STRING (SYMBOL-NAME 'TAGS) "=" @@ -90,10 +91,18 @@ Result](#search-result) object." (IF NOTFLAGGED (CONCATENATE 'STRING "&" (SYMBOL-NAME 'NOTFLAGGED) "=" (FORMAT NIL "~a" NOTFLAGGED)) + "") + (IF NEWEST + (CONCATENATE 'STRING "&" (SYMBOL-NAME 'NEWEST) "=" + (FORMAT NIL "~a" NEWEST)) + "") + (IF ONLYFLAGGED + (CONCATENATE 'STRING "&" (SYMBOL-NAME 'ONLYFLAGGED) + "=" (FORMAT NIL "~a" ONLYFLAGGED)) "")))))) (DEXADOR:GET LAZYBONES-CLIENT.SHARED::REQ-STRING :COOKIE-JAR - LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS - LAZYBONES-CLIENT.SHARED:*HEADERS*))) + LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS + LAZYBONES-CLIENT.SHARED:*HEADERS*))) (DEFUN GET--ONELINERS-ALL-FLAGGED (&KEY LIMIT) @@ -109,8 +118,8 @@ Result](#search-result) object." (FORMAT NIL "~a" LIMIT)) "")))))) (DEXADOR:GET LAZYBONES-CLIENT.SHARED::REQ-STRING :COOKIE-JAR - LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS - LAZYBONES-CLIENT.SHARED:*HEADERS*))) + LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS + LAZYBONES-CLIENT.SHARED:*HEADERS*))) (DEFUN GET--ONELINERS-NEWEST (&KEY LIMIT) @@ -125,8 +134,8 @@ Result](#search-result) object." (FORMAT NIL "~a" LIMIT)) "")))))) (DEXADOR:GET LAZYBONES-CLIENT.SHARED::REQ-STRING :COOKIE-JAR - LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS - LAZYBONES-CLIENT.SHARED:*HEADERS*))) + LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS + LAZYBONES-CLIENT.SHARED:*HEADERS*))) (DEFUN PUT--ONELINER-ENTRY-FLAG (ENTRY &KEY TOKEN VALUE) @@ -146,12 +155,12 @@ Result](#search-result) object." "")))))) (IF LAZYBONES-CLIENT.SHARED:*BODY* (DEXADOR:PUT LAZYBONES-CLIENT.SHARED::REQ-STRING :CONTENT - LAZYBONES-CLIENT.SHARED:*BODY* :COOKIE-JAR - LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS - LAZYBONES-CLIENT.SHARED:*HEADERS*) + LAZYBONES-CLIENT.SHARED:*BODY* :COOKIE-JAR + LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS + LAZYBONES-CLIENT.SHARED:*HEADERS*) (DEXADOR:PUT LAZYBONES-CLIENT.SHARED::REQ-STRING :COOKIE-JAR - LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS - LAZYBONES-CLIENT.SHARED:*HEADERS*)))) + LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS + LAZYBONES-CLIENT.SHARED:*HEADERS*)))) (DEFUN GET--ONELINER-ENTRY (ENTRY) @@ -160,8 +169,8 @@ Result](#search-result) object." (APPLY #'CONCATENATE 'STRING LAZYBONES-CLIENT.SHARED:*HOST* "/api" (FORMAT NIL "/oneliner/~a" ENTRY) NIL))) (DEXADOR:GET LAZYBONES-CLIENT.SHARED::REQ-STRING :COOKIE-JAR - LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS - LAZYBONES-CLIENT.SHARED:*HEADERS*))) + LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS + LAZYBONES-CLIENT.SHARED:*HEADERS*))) (DEFUN PATCH--ONELINER-ENTRY-EDIT (ENTRY &KEY TOKEN) @@ -177,12 +186,12 @@ Result](#search-result) object." "")))))) (IF LAZYBONES-CLIENT.SHARED:*BODY* (DEXADOR:PATCH LAZYBONES-CLIENT.SHARED::REQ-STRING :CONTENT - LAZYBONES-CLIENT.SHARED:*BODY* :COOKIE-JAR - LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS - LAZYBONES-CLIENT.SHARED:*HEADERS*) + LAZYBONES-CLIENT.SHARED:*BODY* :COOKIE-JAR + LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS + LAZYBONES-CLIENT.SHARED:*HEADERS*) (DEXADOR:PATCH LAZYBONES-CLIENT.SHARED::REQ-STRING :COOKIE-JAR - LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS - LAZYBONES-CLIENT.SHARED:*HEADERS*)))) + LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS + LAZYBONES-CLIENT.SHARED:*HEADERS*)))) (DEFUN PUT--ONELINER-ONELINER-LOCKED (ONELINER &KEY TOKEN VALUE) @@ -202,12 +211,12 @@ Result](#search-result) object." "")))))) (IF LAZYBONES-CLIENT.SHARED:*BODY* (DEXADOR:PUT LAZYBONES-CLIENT.SHARED::REQ-STRING :CONTENT - LAZYBONES-CLIENT.SHARED:*BODY* :COOKIE-JAR - LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS - LAZYBONES-CLIENT.SHARED:*HEADERS*) + LAZYBONES-CLIENT.SHARED:*BODY* :COOKIE-JAR + LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS + LAZYBONES-CLIENT.SHARED:*HEADERS*) (DEXADOR:PUT LAZYBONES-CLIENT.SHARED::REQ-STRING :COOKIE-JAR - LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS - LAZYBONES-CLIENT.SHARED:*HEADERS*)))) + LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS + LAZYBONES-CLIENT.SHARED:*HEADERS*)))) (DEFUN POST--ONELINER (&KEY TOKEN) @@ -223,12 +232,12 @@ Result](#search-result) object." "")))))) (IF LAZYBONES-CLIENT.SHARED:*BODY* (DEXADOR:POST LAZYBONES-CLIENT.SHARED::REQ-STRING :CONTENT - LAZYBONES-CLIENT.SHARED:*BODY* :COOKIE-JAR - LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS - LAZYBONES-CLIENT.SHARED:*HEADERS*) + LAZYBONES-CLIENT.SHARED:*BODY* :COOKIE-JAR + LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS + LAZYBONES-CLIENT.SHARED:*HEADERS*) (DEXADOR:POST LAZYBONES-CLIENT.SHARED::REQ-STRING :COOKIE-JAR - LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS - LAZYBONES-CLIENT.SHARED:*HEADERS*)))) + LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS + LAZYBONES-CLIENT.SHARED:*HEADERS*)))) (DEFUN DELETE--ONELINER-ONELINER (ONELINER &KEY TOKEN) @@ -243,8 +252,8 @@ Result](#search-result) object." (FORMAT NIL "~a" TOKEN)) "")))))) (DEXADOR:DELETE LAZYBONES-CLIENT.SHARED::REQ-STRING :COOKIE-JAR - LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS - LAZYBONES-CLIENT.SHARED:*HEADERS*))) + LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS + LAZYBONES-CLIENT.SHARED:*HEADERS*))) (DEFUN POST--INVITE (&KEY TOKEN) @@ -260,12 +269,12 @@ Result](#search-result) object." "")))))) (IF LAZYBONES-CLIENT.SHARED:*BODY* (DEXADOR:POST LAZYBONES-CLIENT.SHARED::REQ-STRING :CONTENT - LAZYBONES-CLIENT.SHARED:*BODY* :COOKIE-JAR - LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS - LAZYBONES-CLIENT.SHARED:*HEADERS*) + LAZYBONES-CLIENT.SHARED:*BODY* :COOKIE-JAR + LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS + LAZYBONES-CLIENT.SHARED:*HEADERS*) (DEXADOR:POST LAZYBONES-CLIENT.SHARED::REQ-STRING :COOKIE-JAR - LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS - LAZYBONES-CLIENT.SHARED:*HEADERS*)))) + LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS + LAZYBONES-CLIENT.SHARED:*HEADERS*)))) (DEFUN DELETE--ACCESS-ACCESS (ACCESS &KEY TOKEN) @@ -280,8 +289,8 @@ Result](#search-result) object." (FORMAT NIL "~a" TOKEN)) "")))))) (DEXADOR:DELETE LAZYBONES-CLIENT.SHARED::REQ-STRING :COOKIE-JAR - LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS - LAZYBONES-CLIENT.SHARED:*HEADERS*))) + LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS + LAZYBONES-CLIENT.SHARED:*HEADERS*))) (DEFUN POST--ACCESS () @@ -291,12 +300,12 @@ Result](#search-result) object." (FORMAT NIL "/access") NIL))) (IF LAZYBONES-CLIENT.SHARED:*BODY* (DEXADOR:POST LAZYBONES-CLIENT.SHARED::REQ-STRING :CONTENT - LAZYBONES-CLIENT.SHARED:*BODY* :COOKIE-JAR - LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS - LAZYBONES-CLIENT.SHARED:*HEADERS*) + LAZYBONES-CLIENT.SHARED:*BODY* :COOKIE-JAR + LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS + LAZYBONES-CLIENT.SHARED:*HEADERS*) (DEXADOR:POST LAZYBONES-CLIENT.SHARED::REQ-STRING :COOKIE-JAR - LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS - LAZYBONES-CLIENT.SHARED:*HEADERS*)))) + LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS + LAZYBONES-CLIENT.SHARED:*HEADERS*)))) (DEFUN POST--INVITE-REDEEM-CODE (CODE) @@ -306,12 +315,12 @@ Result](#search-result) object." (FORMAT NIL "/invite/redeem/~a" CODE) NIL))) (IF LAZYBONES-CLIENT.SHARED:*BODY* (DEXADOR:POST LAZYBONES-CLIENT.SHARED::REQ-STRING :CONTENT - LAZYBONES-CLIENT.SHARED:*BODY* :COOKIE-JAR - LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS - LAZYBONES-CLIENT.SHARED:*HEADERS*) + LAZYBONES-CLIENT.SHARED:*BODY* :COOKIE-JAR + LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS + LAZYBONES-CLIENT.SHARED:*HEADERS*) (DEXADOR:POST LAZYBONES-CLIENT.SHARED::REQ-STRING :COOKIE-JAR - LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS - LAZYBONES-CLIENT.SHARED:*HEADERS*)))) + LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS + LAZYBONES-CLIENT.SHARED:*HEADERS*)))) (DEFUN PUT--CONTRIBUTOR-WHO-SIGNATURE (WHO &KEY TOKEN) @@ -327,16 +336,18 @@ Result](#search-result) object." "")))))) (IF LAZYBONES-CLIENT.SHARED:*BODY* (DEXADOR:PUT LAZYBONES-CLIENT.SHARED::REQ-STRING :CONTENT - LAZYBONES-CLIENT.SHARED:*BODY* :COOKIE-JAR - LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS - LAZYBONES-CLIENT.SHARED:*HEADERS*) + LAZYBONES-CLIENT.SHARED:*BODY* :COOKIE-JAR + LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS + LAZYBONES-CLIENT.SHARED:*HEADERS*) (DEXADOR:PUT LAZYBONES-CLIENT.SHARED::REQ-STRING :COOKIE-JAR - LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS - LAZYBONES-CLIENT.SHARED:*HEADERS*)))) + LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS + LAZYBONES-CLIENT.SHARED:*HEADERS*)))) (DEFUN PUT--CONTRIBUTOR-WHO-PASSWORD (WHO &KEY VALUE REPEATED CURRENT TOKEN) - "Change a contributor's password." + "Change a contributor's password. CURRENT is the current +password. VALUE is the new password. REPEATED must match VALUE. TOKEN +is an API Access token." (LET ((LAZYBONES-CLIENT.SHARED::REQ-STRING (APPLY #'CONCATENATE 'STRING LAZYBONES-CLIENT.SHARED:*HOST* "/api" (FORMAT NIL "/contributor/~a/password" WHO) @@ -360,12 +371,12 @@ Result](#search-result) object." "")))))) (IF LAZYBONES-CLIENT.SHARED:*BODY* (DEXADOR:PUT LAZYBONES-CLIENT.SHARED::REQ-STRING :CONTENT - LAZYBONES-CLIENT.SHARED:*BODY* :COOKIE-JAR - LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS - LAZYBONES-CLIENT.SHARED:*HEADERS*) + LAZYBONES-CLIENT.SHARED:*BODY* :COOKIE-JAR + LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS + LAZYBONES-CLIENT.SHARED:*HEADERS*) (DEXADOR:PUT LAZYBONES-CLIENT.SHARED::REQ-STRING :COOKIE-JAR - LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS - LAZYBONES-CLIENT.SHARED:*HEADERS*)))) + LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS + LAZYBONES-CLIENT.SHARED:*HEADERS*)))) (DEFUN PUT--CONTRIBUTOR-WHO-LOCKED (WHO &KEY VALUE TOKEN) @@ -386,12 +397,12 @@ contributor for making edits or adding new oneliners." "")))))) (IF LAZYBONES-CLIENT.SHARED:*BODY* (DEXADOR:PUT LAZYBONES-CLIENT.SHARED::REQ-STRING :CONTENT - LAZYBONES-CLIENT.SHARED:*BODY* :COOKIE-JAR - LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS - LAZYBONES-CLIENT.SHARED:*HEADERS*) + LAZYBONES-CLIENT.SHARED:*BODY* :COOKIE-JAR + LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS + LAZYBONES-CLIENT.SHARED:*HEADERS*) (DEXADOR:PUT LAZYBONES-CLIENT.SHARED::REQ-STRING :COOKIE-JAR - LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS - LAZYBONES-CLIENT.SHARED:*HEADERS*)))) + LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS + LAZYBONES-CLIENT.SHARED:*HEADERS*)))) (DEFUN GET--CONTRIBUTOR-WHO (WHO) @@ -400,6 +411,27 @@ contributor for making edits or adding new oneliners." (APPLY #'CONCATENATE 'STRING LAZYBONES-CLIENT.SHARED:*HOST* "/api" (FORMAT NIL "/contributor/~a" WHO) NIL))) (DEXADOR:GET LAZYBONES-CLIENT.SHARED::REQ-STRING :COOKIE-JAR - LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS - LAZYBONES-CLIENT.SHARED:*HEADERS*))) + LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS + LAZYBONES-CLIENT.SHARED:*HEADERS*))) + + +(DEFUN POST--SNAPSHOT (&KEY TOKEN) + "Snapshot the datastore. Do this after upgrade" + (LET ((LAZYBONES-CLIENT.SHARED::REQ-STRING + (APPLY #'CONCATENATE 'STRING LAZYBONES-CLIENT.SHARED:*HOST* "/api" + (FORMAT NIL "/snapshot") + (WHEN (OR TOKEN) + (LIST "?" + (IF TOKEN + (CONCATENATE 'STRING (SYMBOL-NAME 'TOKEN) "=" + (FORMAT NIL "~a" TOKEN)) + "")))))) + (IF LAZYBONES-CLIENT.SHARED:*BODY* + (DEXADOR:POST LAZYBONES-CLIENT.SHARED::REQ-STRING :CONTENT + LAZYBONES-CLIENT.SHARED:*BODY* :COOKIE-JAR + LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS + LAZYBONES-CLIENT.SHARED:*HEADERS*) + (DEXADOR:POST LAZYBONES-CLIENT.SHARED::REQ-STRING :COOKIE-JAR + LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS + LAZYBONES-CLIENT.SHARED:*HEADERS*)))) diff --git a/src/lib.lisp b/src/lib.lisp index 9fd75a8..30c953d 100644 --- a/src/lib.lisp +++ b/src/lib.lisp @@ -570,7 +570,7 @@ and, failing that, try to fetch from configured server." (api:get--oneliners-all-flagged)))) (cache-and-print-search-response response)))) -(defun search-for-oneliners (terms limit not-flagged-p) +(defun search-for-oneliners (terms limit not-flagged-p all-flagged-p newestp) (assert (loop for term in terms never (find #\, term) )) (set-term-width) (ensure-config) @@ -579,7 +579,9 @@ and, failing that, try to fetch from configured server." (:host (host)) (api:get--oneliners :tags (str:join "," terms) :limit limit - :notflagged (if not-flagged-p "true" "false"))))) + :notflagged (if not-flagged-p "true" "false") + :newest (if newestp "true" "false") + :onlyflagged (if all-flagged-p "true" "false"))))) (cache-and-print-search-response response))) ;;; RUNNING THINGS IN THE SHELL. |