aboutsummaryrefslogtreecommitdiff
path: root/src/lib.lisp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib.lisp')
-rw-r--r--src/lib.lisp41
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