diff options
author | Colin Okay <okay@toyful.space> | 2022-02-28 11:47:26 -0600 |
---|---|---|
committer | Colin Okay <okay@toyful.space> | 2022-02-28 11:47:26 -0600 |
commit | 670428d3c4fa8280fb415dad61badd4f283d3a55 (patch) | |
tree | 2ad321218ee11da8ac5e9d9e4867c99f9946a8cf /src/lib.lisp | |
parent | 30b5f65fd5c89dda8081058ab62da5e1d78335fe (diff) |
new config creation wizard
Diffstat (limited to 'src/lib.lisp')
-rw-r--r-- | src/lib.lisp | 41 |
1 files changed, 28 insertions, 13 deletions
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 |