summaryrefslogtreecommitdiff
path: root/neocities
diff options
context:
space:
mode:
authorEkaitz Zarraga <ekaitz@elenq.tech>2023-09-30 22:41:10 +0200
committerEkaitz Zarraga <ekaitz@elenq.tech>2023-10-02 21:48:41 +0200
commit178ced05f04d3fcabf0837b3bf133c20d0d9b986 (patch)
treef38f34272a5eefbb76591a0c889e0517ed9de771 /neocities
parent83bc473966e4a2dfbc1aaab4e398adb10e5491fc (diff)
cli: rework and add info command
Diffstat (limited to 'neocities')
-rw-r--r--neocities/cli.scm38
1 files changed, 26 insertions, 12 deletions
diff --git a/neocities/cli.scm b/neocities/cli.scm
index 706e715..1d51892 100644
--- a/neocities/cli.scm
+++ b/neocities/cli.scm
@@ -21,22 +21,38 @@
(define %api (make-neocities-api %host %auth))
+;; TODO MAKE MACRO: if-neocities-success?
+;(define-syntax (syntax-rules))
+
(define (neocities-cmd-list args)
- (when (not (= 1 (length args)))
- (format (current-error-port) "USAGE: neocities list DIRECTORY~&")
+ (when (< 1 (length args))
+ (format (current-error-port) "USAGE: neocities list [DIRECTORY]~&")
(exit 1))
- (neocities-list %api (car args)))
+ (let ((result (neocities-list %api (and (not (null? args)) (car args)))))
+ (if (neocities-success? result)
+ (display (assoc-ref result 'files)) ;; TODO Display in table
+ (format (current-error-port) "Not successful"))))
(define (neocities-cmd-key args)
(when (not (= 0 (length args)))
(format (current-error-port) "USAGE: neocities key~&")
(exit 1))
- (let ((key-pair (assoc "api_key" (neocities-key %api))))
- (format #t "~a~&" (cdr key-pair))))
+ (let ((result (neocities-key %api)))
+ (if (neocities-success? result)
+ (format #t "~a~&" (assoc-ref result "api_key"))
+ (format (current-error-port) "Not successful"))))
+
+(define (neocities-cmd-info args)
+ (when (not (= 0 (length args)))
+ (format (current-error-port) "USAGE: neocities info~&")
+ (exit 1))
+ (let ((result (neocities-info %api)))
+ (if (neocities-success? result)
+ (display (assoc-ref result "info")) ;; TODO display in table
+ (format (current-error-port) "Not successful"))))
-(define (neocities-cmd-upload args) #f)
(define (neocities-cmd-delete args) #f)
-(define (neocities-cmd-info args) #f)
+(define (neocities-cmd-upload args) #f)
(define (command-not-known command)
(format (current-error-port) "Command not known ~A~&" command)
@@ -50,9 +66,7 @@
(info . ,neocities-cmd-info)
(key . ,neocities-cmd-key)))
-(define (lookup-command command)
- (let ((value (assoc command neocities-commands)))
- (and value (cdr value))))
-
(define (neocities-run command args)
- ((or (lookup-command command) (command-not-known command)) args))
+ ((or (assoc-ref neocities-commands command)
+ (command-not-known command))
+ args))