aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--clpmfile.lock22
-rw-r--r--src/lib.lisp71
2 files changed, 59 insertions, 34 deletions
diff --git a/clpmfile.lock b/clpmfile.lock
index fcada2c..8c3a9eb 100644
--- a/clpmfile.lock
+++ b/clpmfile.lock
@@ -33,15 +33,15 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
:releases
-("alexandria" :version "2021-12-09" :source "quicklisp" :systems ("alexandria"))
+("alexandria" :version "2022-02-20" :source "quicklisp" :systems ("alexandria"))
("babel" :version "2020-09-25" :source "quicklisp" :systems ("babel"))
("bordeaux-threads" :version "2020-06-10" :source "quicklisp" :systems
("bordeaux-threads"))
("cffi" :version "2021-04-11" :source "quicklisp" :systems
("cffi" "cffi-grovel" "cffi-toolchain"))
-("chipz" :version "2021-08-07" :source "quicklisp" :systems ("chipz"))
+("chipz" :version "2022-02-20" :source "quicklisp" :systems ("chipz"))
("chunga" :version "2020-04-27" :source "quicklisp" :systems ("chunga"))
-("cl+ssl" :version "2021-12-30" :source "quicklisp" :systems ("cl+ssl"))
+("cl+ssl" :version "2022-02-20" :source "quicklisp" :systems ("cl+ssl"))
("cl-annot" :version "2015-06-08" :source "quicklisp" :systems ("cl-annot"))
("cl-base64" :version "2020-10-16" :source "quicklisp" :systems ("cl-base64"))
("cl-change-case" :version "2021-04-11" :source "quicklisp" :systems
@@ -50,31 +50,31 @@
("net.didierverna.clon" "net.didierverna.clon.core"
"net.didierverna.clon.setup" "net.didierverna.clon.setup/termio"))
("cl-cookie" :version "2019-10-07" :source "quicklisp" :systems ("cl-cookie"))
-("cl-ppcre" :version "2019-05-21" :source "quicklisp" :systems
+("cl-ppcre" :version "2022-02-20" :source "quicklisp" :systems
("cl-ppcre" "cl-ppcre-unicode"))
-("cl-str" :version "2021-05-31" :source "quicklisp" :systems ("str"))
+("cl-str" :version "2022-02-20" :source "quicklisp" :systems ("str"))
("cl-syntax" :version "2015-04-07" :source "quicklisp" :systems
("cl-syntax" "cl-syntax-annot"))
("cl-unicode" :version "2021-02-28" :source "quicklisp" :systems ("cl-unicode"))
("cl-utilities" :version "2010-10-07" :source "quicklisp" :systems
("cl-utilities"))
-("dexador" :version "2021-12-09" :source "quicklisp" :systems ("dexador"))
+("dexador" :version "2022-02-20" :source "quicklisp" :systems ("dexador"))
("didierverna/clon" :version "20210424171500" :source "ultralisp" :systems
("net.didierverna.clon.termio"))
("fast-http" :version "2019-10-07" :source "quicklisp" :systems ("fast-http"))
("fast-io" :version "2020-09-25" :source "quicklisp" :systems ("fast-io"))
-("flexi-streams" :version "2021-08-07" :source "quicklisp" :systems
+("flexi-streams" :version "2022-02-20" :source "quicklisp" :systems
("flexi-streams"))
("jonathan" :version "2020-09-25" :source "quicklisp" :systems ("jonathan"))
("local-time" :version "2021-01-24" :source "quicklisp" :systems ("local-time"))
("magic-ed" :version "2020-03-25" :source "quicklisp" :systems ("magic-ed"))
-("named-readtables" :version "2021-12-09" :source "quicklisp" :systems
+("named-readtables" :version "2022-02-20" :source "quicklisp" :systems
("named-readtables"))
("oneliners.api-client.asd" :version :newest :source :implicit-file :systems
("oneliners.api-client"))
("oneliners.cli.asd" :version :newest :source :implicit-file :systems
("oneliners.cli"))
-("osicat" :version "2021-12-09" :source "quicklisp" :systems ("osicat"))
+("osicat" :version "2022-02-20" :source "quicklisp" :systems ("osicat"))
("proc-parse" :version "2019-08-13" :source "quicklisp" :systems ("proc-parse"))
("quri" :version "2021-06-30" :source "quicklisp" :systems ("quri"))
("smart-buffer" :version "2021-10-21" :source "quicklisp" :systems
@@ -251,7 +251,9 @@
((:system :name "cffi") (:system :name "trivial-features"))
((:system :name "babel") (:system :name "trivial-features")))
-("trivial-garbage" ((:system :name "cl+ssl") (:system :name "trivial-garbage")))
+("trivial-garbage"
+ ((:system :name "dexador") (:system :name "trivial-garbage"))
+ ((:system :name "cl+ssl") (:system :name "trivial-garbage")))
("trivial-gray-streams"
((:system :name "flexi-streams") (:system :name "trivial-gray-streams"))
diff --git a/src/lib.lisp b/src/lib.lisp
index b8c7343..d174c6a 100644
--- a/src/lib.lisp
+++ b/src/lib.lisp
@@ -53,10 +53,14 @@
(setf (getf *config* :api-token) newval))
(defun make-temp-file-name ()
- (merge-pathnames (format nil "~a" (gensym "oneliners")) (uiop:temporary-directory)))
+ (namestring
+ (merge-pathnames (format nil "~a" (gensym "oneliners")) (uiop:temporary-directory))))
(defun string-from-editor ()
- (magic-ed:magic-ed make-temp-file-name :eval nil :output :string))
+ (let ((filename (make-temp-file-name)))
+ (unwind-protect
+ (magic-ed:magic-ed filename :eval nil :output :string)
+ (uiop:delete-file-if-exists filename))))
(defun config-file ()
(merge-pathnames ".config/oneliners.config" (user-homedir-pathname)))
@@ -111,24 +115,19 @@ the directories that appear in the value of that variable."
(append init-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?")
+ (explanation
+ (when (y-or-n-p "Provide an explanation?")
(string-from-editor))))
- (format t "Adding a new oneliner.~%~s~%"
- (list :oneliners oneliner
- :tags tags
- :brief brief
- :explanation explaination))
-
- ;; (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~%")))
+ (api:request-with
+ (:host (host)
+ :body (jonathan:to-json
+ (list :oneliner oneliner
+ :tags tags
+ :brief brief
+ :explanation explanation))
+ :content-type "application/json")
+ (api:post--add-oneliner :token (api-token))
+ (format t "Added~%"))))
(defun request-invite-code ()
(ensure-config)
@@ -156,14 +155,38 @@ the directories that appear in the value of that variable."
:password1 pass
:password2 pass)))
+(defun cache-search-results-to-last-search-file (results)
+ (with-open-file (output (last-search-file) :direction :output :if-exists :supersede)
+ (print results output)))
+
+(defun print-oneliner-result-for-user (number oneliner)
+ (format t "~3a~a~a: ~a"
+ number
+ (if (getf oneliner :isflagged)
+ "⚠" " ")
+ (if (getf oneliner :islocked)
+ "🔒" " ")
+ (getf oneliner :brief))
+ (format t "~% ~a~%~%" (getf oneliner :oneliner)))
+
(defun search-for-oneliners (terms limit not-flagged-p)
(assert (loop for term in terms never (find #\, term) ))
(ensure-config)
- (print (api:request-with
- (:host (host))
- (api:get--search :tags (str:join "," terms)
- :limit limit
- :notflagged (if not-flagged-p "true" "false")))))
+ (let ((response
+ (api:request-with
+ (:host (host))
+ (api:get--search :tags (str:join "," terms)
+ :limit limit
+ :notflagged (if not-flagged-p "true" "false")))))
+ (handler-case
+ (a:when-let (oneliners
+ (getf (jonathan:parse response) :oneliners))
+ (cache-search-results-to-last-search-file
+ (loop for number from 1
+ for oneliner in oneliners
+ collect (list* :result-number number oneliner)
+ do (print-oneliner-result-for-user number oneliner)))))))
+
;;; RUNNING COMMANDS