aboutsummaryrefslogtreecommitdiff
path: root/lib/client.lisp
diff options
context:
space:
mode:
authorColin Okay <okay@toyful.space>2022-03-11 09:22:58 -0600
committerColin Okay <okay@toyful.space>2022-03-11 09:22:58 -0600
commit8f9b59690660f85aeae675989fe9fe6b1b830445 (patch)
treef05b323c50385de88a4762a9c1ee370ae6cf100f /lib/client.lisp
parente73fed7afb45d37a248f7b95d4a51bb4807a14a2 (diff)
separated app from lib systems; added with-client-state
Diffstat (limited to 'lib/client.lisp')
-rw-r--r--lib/client.lisp50
1 files changed, 35 insertions, 15 deletions
diff --git a/lib/client.lisp b/lib/client.lisp
index f49201a..0c4c362 100644
--- a/lib/client.lisp
+++ b/lib/client.lisp
@@ -1,4 +1,4 @@
-;;;; main.lisp -- oneliners.cli entrypoint
+;;;; main.lisp -- client actions
;; Copyright (C) 2022 Colin Okay
@@ -16,7 +16,32 @@
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
(in-package :oneliners.cli)
-;;; CONFIG AND RESULTS FILE LOCATIONS
+;;; SEARCHING FOR ONELINERS
+
+(defun search-for-oneliners (terms limit &optional not-flagged-p all-flagged-p newestp)
+ (assert (loop for term in terms never (find #\, term)) () "Search terms may not contain commas.")
+ (with-local-state ()
+ (api:get--oneliners :tags (str:join "," terms)
+ :limit limit
+ :notflagged (true-or-false not-flagged-p)
+ :newest (true-or-false newestp)
+ :onlyflagged (true-or-false all-flagged-p))))
+
+(defun search-for-oneliners (terms limit not-flagged-p all-flagged-p newestp)
+
+ (set-term-width)
+ (ensure-config)
+ (let ((response
+ (api:request-with
+ (:host (host))
+ (api:get--oneliners :tags (str:join "," terms)
+ :limit limit
+ :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)))
+
+
(defvar *ol-output-timeout* 1)
@@ -175,6 +200,13 @@ and, failing that, try to fetch from configured server."
explanation)))
(terpri))))
+(defun tags-from-oneliner (string)
+ "Splits a string using consequitive whitespace as a separator,
+returning a set of tags"
+ (remove-duplicates
+ (remove-if-not #'executable-on-system-p (ppcre:split " +" string))
+ :test #'equal))
+
(defun add-new-oneliner ()
(ensure-config)
@@ -433,19 +465,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 all-flagged-p newestp)
- (assert (loop for term in terms never (find #\, term) ))
- (set-term-width)
- (ensure-config)
- (let ((response
- (api:request-with
- (:host (host))
- (api:get--oneliners :tags (str:join "," terms)
- :limit limit
- :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.