From 5c590a614544c977964692e41b0e5c19043b142c Mon Sep 17 00:00:00 2001 From: Colin Okay Date: Thu, 4 Aug 2022 10:54:39 -0500 Subject: [wip] working on clingon refactor --- app/search.lisp | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 app/search.lisp (limited to 'app/search.lisp') diff --git a/app/search.lisp b/app/search.lisp new file mode 100644 index 0000000..015a749 --- /dev/null +++ b/app/search.lisp @@ -0,0 +1,76 @@ +;;;; search.lisp -- search function interface for oneliners wiki cli + +(in-package :oneliners.cli.app ) + +(defun search/options () + "Returns a list of options for the search command." + (list + (cli:make-option + :integer + :short-name #\l + :long-name "limit" + :description "number of results to return" + :initial-value 10 + :key :limit) + (cli:make-option + :flag + :short-name #\f + :long-name "flagged" + :description "only flagged oneliners are returned" + :key :flagged) + (cli:make-option + :flag + :short-name #\F + :long-name "no-flagged" + :description "only unflagged oneliners are returned" + :key :no-flagged) + (cli:make-option + :flag + :short-name #\n + :long-name "newest" + :description "the newest matching oneliners are returned" + :key :newest))) + +(defun search/handler (cmd) + "Handler function for the search command. " + (let ((args + (cli:command-arguments cmd)) + (limit + (cli:getopt cmd :limit))) + (cond + (args + ;; if there are search terms, call the main search function + (ol:search-for-oneliners + args + limit + (cli:getopt cmd :no-flagged) + (cli:getopt cmd :flagged) + (cli:getopt cmd :newest))) + + ;; if no search terms, but --newest or -n + ((cli:getopt cmd :newest) + (ol::newest-oneliners limit)) + + ;; no args, but --flagged or -f + ((cli:getopt cmd :flagged) + (ol::all-flagged-oneliners limit)) + + (t + (cli::print-usage-and-exit cmd t))))) + + +(defparameter +search/examples+ + '(("Search for oneliners involving grep and awk" . + "ol search grep awk") + ("Limit search to flagged oneliners (useful for contributors)" . + "ol search --flagged grep awk"))) + + +(defun search/command () + "Creates a new command for interfacing with the search api." + (cli:make-command + :name "search" + :description "search for oneliners with provided tags" + :options (search/options) + :handler #'search/handler + :examples +search/examples+)) -- cgit v1.2.3