diff options
author | Ekaitz Zarraga <ekaitz@elenq.tech> | 2023-09-30 21:12:12 +0200 |
---|---|---|
committer | Ekaitz Zarraga <ekaitz@elenq.tech> | 2023-10-02 21:48:41 +0200 |
commit | 8e72aa3be2c71846346f9131c074daf44a73459a (patch) | |
tree | 669b5ba0a5adc7ced435ac55af90525adac014fd /neocities | |
parent | afc427d37b41bd5f6a3d6d13b13062c48b967aac (diff) |
neocities: add cli tool: key subcommand works
Diffstat (limited to 'neocities')
-rw-r--r-- | neocities/cli.scm | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/neocities/cli.scm b/neocities/cli.scm new file mode 100644 index 0000000..706e715 --- /dev/null +++ b/neocities/cli.scm @@ -0,0 +1,58 @@ +(define-module (neocities cli) + #:use-module (neocities api) + #:use-module (ice-9 format) + #:export ( + neocities-run +)) + +(define %user (getenv "NEOCITIES_USER")) +(define %pass (getenv "NEOCITIES_PASS")) +(define %key (getenv "NEOCITIES_KEY")) +(define %host (or (getenv "NEOCITIES_HOST") "neocities.org")) + +(define %auth + (cond + (%key (make-neocities-auth-api-key %key)) + ((and %user %pass) (make-neocities-auth-basic %user %pass)) + (else (begin + (format (current-error-port) "ERROR: Missing authentication method~&") + (exit 1))))) + +(define %api (make-neocities-api %host %auth)) + + +(define (neocities-cmd-list args) + (when (not (= 1 (length args))) + (format (current-error-port) "USAGE: neocities list DIRECTORY~&") + (exit 1)) + (neocities-list %api (car args))) + +(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)))) + +(define (neocities-cmd-upload args) #f) +(define (neocities-cmd-delete args) #f) +(define (neocities-cmd-info args) #f) + +(define (command-not-known command) + (format (current-error-port) "Command not known ~A~&" command) + (exit 1)) + +;; TODO: generate docs automatically from here? +(define neocities-commands + `((list . ,neocities-cmd-list) + (upload . ,neocities-cmd-upload) + (delete . ,neocities-cmd-delete) + (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)) |