From 670428d3c4fa8280fb415dad61badd4f283d3a55 Mon Sep 17 00:00:00 2001 From: Colin Okay Date: Mon, 28 Feb 2022 11:47:26 -0600 Subject: new config creation wizard --- src/lib.lisp | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/lib.lisp b/src/lib.lisp index 8dbbbc9..b49f8c2 100644 --- a/src/lib.lisp +++ b/src/lib.lisp @@ -13,30 +13,35 @@ (defvar *config* nil "A configuration plist") -(defun make-config (&key host api-token editor (shell "bash")) - (append (when host (list :host host)) - (when api-token (list :api-token api-token)) - (when editor (list :editor editor)) - (list :shell shell))) - (defun valid-config-p (config) (and (listp config) (evenp (length config)) (stringp (getf config :host)) t)) -(defun write-default-config-to-disk () - (let ((conf-file (config-file))) - (ensure-directories-exist conf-file) - (with-open-file (out conf-file :direction :output) - (print (make-config :host "http://localhost:8888") out)))) - (defun write-config-to-disk () (let ((conf-file (config-file))) (ensure-directories-exist conf-file) (with-open-file (out conf-file :direction :output :if-exists :supersede) (print *config* out)))) +(defun make-config (&key host api-token editor (shell "bash")) + (append (when host (list :host host)) + (when api-token (list :api-token api-token)) + (list :shell shell))) + +(defun make-fresh-config () + (format t "No configuration file has been found. Running Setup~%~%") + (setf *config* + (make-config + :host (prompt "Oneliner Instance Host: " + :prefill "https://oneliners.wiki") + :shell (prompt "With which shell should commands be run: " + :prefill "bash"))) + (write-config-to-disk) + (format t "Configuration has been written to ~a~%. Edit this at any time.~%~%" + (config-file))) + (defun fetch-config-from-disk () (let ((conf (uiop:with-safe-io-syntax () @@ -46,7 +51,7 @@ (defun ensure-config () (unless (uiop:file-exists-p (config-file)) - (write-default-config-to-disk)) + (make-fresh-config)) (fetch-config-from-disk)) (defun host () (getf *config* :host)) @@ -415,6 +420,16 @@ the directories that appear in the value of that variable." collect (list* :result-number number oneliner) do (print-oneliner-result-for-user number oneliner)))) +(defun newest-oneliners (&optional limit) + (ensure-config) + (api:request-with + (:host (host)) + (let ((response + (if limit + (api:get--oneliners-newest :limit limit) + (api:get--oneliners-newest)))) + (cache-and-print-search-response response)))) + (defun all-flagged-oneliners (&optional limit) (ensure-config) (api:request-with -- cgit v1.2.3