From 8f9b59690660f85aeae675989fe9fe6b1b830445 Mon Sep 17 00:00:00 2001 From: Colin Okay Date: Fri, 11 Mar 2022 09:22:58 -0600 Subject: separated app from lib systems; added with-client-state --- lib/client.lisp | 50 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 15 deletions(-) (limited to 'lib/client.lisp') 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 . (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. -- cgit v1.2.3