diff options
Diffstat (limited to 'lib/client.lisp')
-rw-r--r-- | lib/client.lisp | 50 |
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. |