aboutsummaryrefslogtreecommitdiff
path: root/app/search.lisp
diff options
context:
space:
mode:
authorColin Okay <colin@cicadas.surf>2022-08-04 10:54:39 -0500
committerColin Okay <colin@cicadas.surf>2022-08-04 10:54:39 -0500
commit5c590a614544c977964692e41b0e5c19043b142c (patch)
treea37c12305baa48ccf42f58020d6930b2f1bcfb78 /app/search.lisp
parentd0136dac1e04fac93839e3876f711bfa1837141a (diff)
[wip] working on clingon refactor
Diffstat (limited to 'app/search.lisp')
-rw-r--r--app/search.lisp76
1 files changed, 76 insertions, 0 deletions
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+))