diff options
author | Colin Okay <okay@toyful.space> | 2022-02-28 11:47:26 -0600 |
---|---|---|
committer | Colin Okay <okay@toyful.space> | 2022-02-28 11:47:26 -0600 |
commit | 670428d3c4fa8280fb415dad61badd4f283d3a55 (patch) | |
tree | 2ad321218ee11da8ac5e9d9e4867c99f9946a8cf | |
parent | 30b5f65fd5c89dda8081058ab62da5e1d78335fe (diff) |
new config creation wizard
-rw-r--r-- | build-app.lisp | 5 | ||||
-rw-r--r-- | oneliners.api-client.lisp | 241 | ||||
-rw-r--r-- | src/lib.lisp | 41 |
3 files changed, 195 insertions, 92 deletions
diff --git a/build-app.lisp b/build-app.lisp index 793ffae..f0ae688 100644 --- a/build-app.lisp +++ b/build-app.lisp @@ -39,6 +39,8 @@ my1337pw.") :description "Return flagged oneliners. Ignores TAGS. Respects --limit") (flag :long-name "not-flagged" :description "Request that no flagged oneliners are returned.") + (flag :long-name "newest" + :description "Return newest oneliners. Ignores TAGs. Respects --limit up to server specified maxiumum.") (stropt :long-name "brief-like" :argument-name :optional :default-value ".*" @@ -132,6 +134,9 @@ than the users." ((getopt :long-name "all-flagged") (cli::all-flagged-oneliners (getopt :long-name "limit"))) + ((getopt :long-name "newest") + (cli::newest-oneliners (getopt :long-name "limit"))) + (arguments ;; when the first argument is a number, try run a oneliner (a:when-let (hist-number (parse-integer (first arguments) :junk-allowed t)) diff --git a/oneliners.api-client.lisp b/oneliners.api-client.lisp index 0ac2940..e8e1d28 100644 --- a/oneliners.api-client.lisp +++ b/oneliners.api-client.lisp @@ -5,18 +5,22 @@ (defpackage #:ONELINERS.API-CLIENT (:use :cl :lazybones-client.shared) (:export #:*host* #:*body* #:*headers* #:*cookies* #:request-with - #:GET--ONELINERS-ALL-FLAGGED -#:GET--ONLINERS-ALL-FLAGGED -#:GET--ONELINERS + #:GET--ONELINERS +#:GET--ONELINERS-ALL-FLAGGED +#:GET--ONELINERS-NEWEST #:PUT--ONELINER-ENTRY-FLAG #:PATCH--ONELINER-ENTRY-EDIT #:PUT--ONELINER-ONELINER-LOCKED #:POST--ONELINER +#:DELETE--ONELINER-ONELINER #:POST--INVITE #:DELETE--ACCESS-ACCESS #:POST--ACCESS #:POST--INVITE-REDEEM-CODE -#:PUT--CONTRIBUTOR-HANDLE-LOCKED)) +#:PUT--CONTRIBUTOR-WHO-SIGNATURE +#:PUT--CONTRIBUTOR-WHO-PASSWORD +#:PUT--CONTRIBUTOR-WHO-LOCKED +#:GET--CONTRIBUTOR-WHO)) (in-package :ONELINERS.API-CLIENT) @@ -65,29 +69,38 @@ COOKIES should be an instance of CL-COOKIE:COOKIE-JAR. Defaults to (dex:response-body ,http-error-var))))))) -(DEFUN GET--ONELINERS-ALL-FLAGGED (&KEY LIMIT) - "A search endpoint returning all of the flagged oneliners. If LIMIT - is present, only that many are returned." +(DEFUN GET--ONELINERS (&KEY TAGS LIMIT NOTFLAGGED) + "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/all-flagged") - (WHEN (OR LIMIT) + (FORMAT NIL "/oneliners") + (WHEN (OR TAGS LIMIT NOTFLAGGED) (LIST "?" + (IF TAGS + (CONCATENATE 'STRING (SYMBOL-NAME 'TAGS) "=" + (FORMAT NIL "~a" TAGS)) + "") (IF LIMIT - (CONCATENATE 'STRING (SYMBOL-NAME 'LIMIT) "=" + (CONCATENATE 'STRING "&" (SYMBOL-NAME 'LIMIT) "=" (FORMAT NIL "~a" LIMIT)) + "") + (IF NOTFLAGGED + (CONCATENATE 'STRING "&" (SYMBOL-NAME 'NOTFLAGGED) + "=" (FORMAT NIL "~a" NOTFLAGGED)) "")))))) (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--ONLINERS-ALL-FLAGGED (&KEY LIMIT) +(DEFUN GET--ONELINERS-ALL-FLAGGED (&KEY LIMIT) "A search endpoint returning all of the flagged oneliners. If LIMIT is present, only that many are returned." (LET ((LAZYBONES-CLIENT.SHARED::REQ-STRING (APPLY #'CONCATENATE 'STRING LAZYBONES-CLIENT.SHARED:*HOST* "/api" - (FORMAT NIL "/onliners/all-flagged") + (FORMAT NIL "/oneliners/all-flagged") (WHEN (OR LIMIT) (LIST "?" (IF LIMIT @@ -95,38 +108,28 @@ COOKIES should be an instance of CL-COOKIE:COOKIE-JAR. Defaults to (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 (&KEY TAGS LIMIT NOTFLAGGED) - "A search endpoint returning a JSON encoded array of Oneliner -Entries. TAGS cannot be empty. Returns a [Search -Result](#search-result) object." +(DEFUN GET--ONELINERS-NEWEST (&KEY LIMIT) + "A search endpoint returning the LIMIT newest oneliners." (LET ((LAZYBONES-CLIENT.SHARED::REQ-STRING (APPLY #'CONCATENATE 'STRING LAZYBONES-CLIENT.SHARED:*HOST* "/api" - (FORMAT NIL "/oneliners") - (WHEN (OR TAGS LIMIT NOTFLAGGED) + (FORMAT NIL "/oneliners/newest") + (WHEN (OR LIMIT) (LIST "?" - (IF TAGS - (CONCATENATE 'STRING (SYMBOL-NAME 'TAGS) "=" - (FORMAT NIL "~a" TAGS)) - "") (IF LIMIT - (CONCATENATE 'STRING "&" (SYMBOL-NAME 'LIMIT) "=" + (CONCATENATE 'STRING (SYMBOL-NAME 'LIMIT) "=" (FORMAT NIL "~a" LIMIT)) - "") - (IF NOTFLAGGED - (CONCATENATE 'STRING "&" (SYMBOL-NAME 'NOTFLAGGED) - "=" (FORMAT NIL "~a" NOTFLAGGED)) "")))))) (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) - "Flag the oneliner for review." + "Flag / Unflag the oneliner for review." (LET ((LAZYBONES-CLIENT.SHARED::REQ-STRING (APPLY #'CONCATENATE 'STRING LAZYBONES-CLIENT.SHARED:*HOST* "/api" (FORMAT NIL "/oneliner/~a/flag" ENTRY) @@ -142,12 +145,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 PATCH--ONELINER-ENTRY-EDIT (ENTRY &KEY TOKEN) @@ -163,12 +166,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) @@ -188,12 +191,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) @@ -209,12 +212,28 @@ 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) + "Delete a oneliner." + (LET ((LAZYBONES-CLIENT.SHARED::REQ-STRING + (APPLY #'CONCATENATE 'STRING LAZYBONES-CLIENT.SHARED:*HOST* "/api" + (FORMAT NIL "/oneliner/~a" ONELINER) + (WHEN (OR TOKEN) + (LIST "?" + (IF TOKEN + (CONCATENATE 'STRING (SYMBOL-NAME 'TOKEN) "=" + (FORMAT NIL "~a" TOKEN)) + "")))))) + (DEXADOR:DELETE LAZYBONES-CLIENT.SHARED::REQ-STRING :COOKIE-JAR + LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS + LAZYBONES-CLIENT.SHARED:*HEADERS*))) (DEFUN POST--INVITE (&KEY TOKEN) @@ -230,12 +249,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) @@ -250,8 +269,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 () @@ -261,12 +280,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) @@ -276,31 +295,95 @@ 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-HANDLE-LOCKED (HANDLE &KEY VALUE) +(DEFUN PUT--CONTRIBUTOR-WHO-SIGNATURE (WHO &KEY TOKEN) NIL (LET ((LAZYBONES-CLIENT.SHARED::REQ-STRING (APPLY #'CONCATENATE 'STRING LAZYBONES-CLIENT.SHARED:*HOST* "/api" - (FORMAT NIL "/contributor/~a/locked" HANDLE) - (WHEN (OR VALUE) + (FORMAT NIL "/contributor/~a/signature" WHO) + (WHEN (OR TOKEN) + (LIST "?" + (IF TOKEN + (CONCATENATE 'STRING (SYMBOL-NAME 'TOKEN) "=" + (FORMAT NIL "~a" TOKEN)) + "")))))) + (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*) + (DEXADOR:PUT LAZYBONES-CLIENT.SHARED::REQ-STRING :COOKIE-JAR + LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS + LAZYBONES-CLIENT.SHARED:*HEADERS*)))) + + +(DEFUN PUT--CONTRIBUTOR-WHO-PASSWORD (WHO &KEY VALUE REPEATED TOKEN) + NIL + (LET ((LAZYBONES-CLIENT.SHARED::REQ-STRING + (APPLY #'CONCATENATE 'STRING LAZYBONES-CLIENT.SHARED:*HOST* "/api" + (FORMAT NIL "/contributor/~a/password" WHO) + (WHEN (OR VALUE REPEATED TOKEN) (LIST "?" (IF VALUE (CONCATENATE 'STRING (SYMBOL-NAME 'VALUE) "=" (FORMAT NIL "~a" VALUE)) + "") + (IF REPEATED + (CONCATENATE 'STRING "&" (SYMBOL-NAME 'REPEATED) + "=" (FORMAT NIL "~a" REPEATED)) + "") + (IF TOKEN + (CONCATENATE 'STRING "&" (SYMBOL-NAME 'TOKEN) "=" + (FORMAT NIL "~a" TOKEN)) "")))))) (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) + NIL + (LET ((LAZYBONES-CLIENT.SHARED::REQ-STRING + (APPLY #'CONCATENATE 'STRING LAZYBONES-CLIENT.SHARED:*HOST* "/api" + (FORMAT NIL "/contributor/~a/locked" WHO) + (WHEN (OR VALUE TOKEN) + (LIST "?" + (IF VALUE + (CONCATENATE 'STRING (SYMBOL-NAME 'VALUE) "=" + (FORMAT NIL "~a" VALUE)) + "") + (IF TOKEN + (CONCATENATE 'STRING "&" (SYMBOL-NAME 'TOKEN) "=" + (FORMAT NIL "~a" TOKEN)) + "")))))) + (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*) + (DEXADOR:PUT LAZYBONES-CLIENT.SHARED::REQ-STRING :COOKIE-JAR + LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS + LAZYBONES-CLIENT.SHARED:*HEADERS*)))) + + +(DEFUN GET--CONTRIBUTOR-WHO (WHO) + NIL + (LET ((LAZYBONES-CLIENT.SHARED::REQ-STRING + (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*))) diff --git a/src/lib.lisp b/src/lib.lisp index 8dbbbc9..b49f8c2 100644 --- a/src/lib.lisp +++ b/src/lib.lisp @@ -13,30 +13,35 @@ (defvar *config* nil "A configuration plist") -(defun make-config (&key host api-token editor (shell "bash")) - (append (when host (list :host host)) - (when api-token (list :api-token api-token)) - (when editor (list :editor editor)) - (list :shell shell))) - (defun valid-config-p (config) (and (listp config) (evenp (length config)) (stringp (getf config :host)) t)) -(defun write-default-config-to-disk () - (let ((conf-file (config-file))) - (ensure-directories-exist conf-file) - (with-open-file (out conf-file :direction :output) - (print (make-config :host "http://localhost:8888") out)))) - (defun write-config-to-disk () (let ((conf-file (config-file))) (ensure-directories-exist conf-file) (with-open-file (out conf-file :direction :output :if-exists :supersede) (print *config* out)))) +(defun make-config (&key host api-token editor (shell "bash")) + (append (when host (list :host host)) + (when api-token (list :api-token api-token)) + (list :shell shell))) + +(defun make-fresh-config () + (format t "No configuration file has been found. Running Setup~%~%") + (setf *config* + (make-config + :host (prompt "Oneliner Instance Host: " + :prefill "https://oneliners.wiki") + :shell (prompt "With which shell should commands be run: " + :prefill "bash"))) + (write-config-to-disk) + (format t "Configuration has been written to ~a~%. Edit this at any time.~%~%" + (config-file))) + (defun fetch-config-from-disk () (let ((conf (uiop:with-safe-io-syntax () @@ -46,7 +51,7 @@ (defun ensure-config () (unless (uiop:file-exists-p (config-file)) - (write-default-config-to-disk)) + (make-fresh-config)) (fetch-config-from-disk)) (defun host () (getf *config* :host)) @@ -415,6 +420,16 @@ the directories that appear in the value of that variable." collect (list* :result-number number oneliner) do (print-oneliner-result-for-user number oneliner)))) +(defun newest-oneliners (&optional limit) + (ensure-config) + (api:request-with + (:host (host)) + (let ((response + (if limit + (api:get--oneliners-newest :limit limit) + (api:get--oneliners-newest)))) + (cache-and-print-search-response response)))) + (defun all-flagged-oneliners (&optional limit) (ensure-config) (api:request-with |