Normalize docstring formatting.

This commit is contained in:
Jaidyn Levesque 2019-06-06 19:23:55 -05:00
parent 962bfb84ca
commit c533fa3eaf

View File

@ -4,6 +4,7 @@
(defparameter *api-root* "/api/v0/") (defparameter *api-root* "/api/v0/")
;; ————————————————————————————————————— ;; —————————————————————————————————————
;; BASE
;; STRING LIST [:LIST :BOOLEAN :SYMBOL] → STRING | HASHTABLE | (NIL STRING) ;; STRING LIST [:LIST :BOOLEAN :SYMBOL] → STRING | HASHTABLE | (NIL STRING)
(defun ipfs-call (call arguments &key (parameters nil) (want-stream nil) (defun ipfs-call (call arguments &key (parameters nil) (want-stream nil)
@ -68,8 +69,12 @@
(values nil message) (values nil message)
,form))) ,form)))
;; FORM FORM → FORM
(defmacro bind-api-alist (call form) (defmacro bind-api-alist (call form)
`(bind-api-result ,call (re-hash-table-alist ,form))) "Basically #'bind-api-result, but it assumes the final form is a hash-table,
and maps it to an associative list."
`(bind-api-result ,call (ignore-errors (re-hash-table-alist ,form))))
;; ————————————————————————————————————— ;; —————————————————————————————————————
@ -82,7 +87,7 @@
(bind-api-result (bind-api-result
(ipfs-call "add" `(("pin" ,pin) ("only-hash" ,only-hash)) (ipfs-call "add" `(("pin" ,pin) ("only-hash" ,only-hash))
:method :post :parameters `(("file" . ,pathname))) :method :post :parameters `(("file" . ,pathname)))
(re-hash-table-alist result))) result))
;; STRING :NUMBER :NUMBER → STRING || (NIL STRING) ;; STRING :NUMBER :NUMBER → STRING || (NIL STRING)
(defun cat (ipfs-path &key (offset nil) (length nil)) (defun cat (ipfs-path &key (offset nil) (length nil))
@ -129,14 +134,12 @@
;; [STRING] → ALIST ;; [STRING] → ALIST
(defun id (&optional peer-id) (defun id (&optional peer-id)
"Return info on a node by ID. Returns as an associative list, "Return info on a node by ID. Returns as an associative list, the public key,
the public key, agent version, etc. If no node ID is specified, agent version, etc. If no node ID is specified, then your own is assumed.
then your own is assumed.
/ipns/docs.ipfs.io/reference/api/http/#api-v0-id" /ipns/docs.ipfs.io/reference/api/http/#api-v0-id"
(bind-api-result (bind-api-alist
(ipfs-call "id" `(,(if peer-id (list "arg" peer-id)))) (ipfs-call "id" `(,(if peer-id (list "arg" peer-id))))
result))
(re-hash-table-alist result)))
;; —————————————————— ;; ——————————————————
@ -279,8 +282,8 @@
;; NIL → ALIST || (NIL STRING) ;; NIL → ALIST || (NIL STRING)
(defun cid/bases () (defun cid/bases ()
"Return a associative list of available bases in plist format; "Return a associative list of available bases in plist format; each base's
each base's name is a assigned a given code-number. name is a assigned a given code-number.
((CODE-A . NAME-A) (CODE-B . NAME-B) (CODE-N . NAME-N)) ((CODE-A . NAME-A) (CODE-B . NAME-B) (CODE-N . NAME-N))
/ipns/docs.ipfs.io/reference/api/http/#api-v0-cid-bases" /ipns/docs.ipfs.io/reference/api/http/#api-v0-cid-bases"
(bind-api-result (bind-api-result
@ -301,12 +304,12 @@
(bind-api-result (bind-api-result
(ipfs-call "config" `(("arg" ,key) ,(if value (list "value" value)) (ipfs-call "config" `(("arg" ,key) ,(if value (list "value" value))
("bool" ,bool) ("json" ,json))) ("bool" ,bool) ("json" ,json)))
(cons (gethash "Key" result) (gethash "Value" result)))) (gethash "Value" result)))
;; NIL → ALIST ;; NIL → ALIST
(defun config/show () (defun config/show ()
"Return the config file's contents, in alist-format "Return the config file's contents, in alist-format y'know, with several
y'know, with several sub-alists. sub-alists.
Doesn't quite line up with #api-v0-config-show Doesn't quite line up with #api-v0-config-show
/ipns/docs.ipfs.io/reference/api/http/#api-v0-config-show" /ipns/docs.ipfs.io/reference/api/http/#api-v0-config-show"
(bind-api-alist (bind-api-alist
@ -316,15 +319,15 @@
;; STRING → STRING || (NIL STRING) ;; STRING → STRING || (NIL STRING)
(defun config/get (key) (defun config/get (key)
"Get a config key's value. "Get a config key's value.
Doesn't map with any existant API call; it's just a Doesn't map with any existant API call; it's just a convenience wrapper
convenience wrapper around #'config" around #'config."
(config key)) (config key))
;; STRING → STRING || (NIL STRING) ;; STRING → STRING || (NIL STRING)
(defun config/set (key value &key (bool nil) (json nil)) (defun config/set (key value &key (bool nil) (json nil))
"Set a config key's value. "Set a config key's value.
Doesn't map with any existant API call; it's just a Doesn't map with any existant API call; it's just a convenience wrapper
convenience wrapper around #'config" around #'config."
(config key :value value :bool bool :json json)) (config key :value value :bool bool :json json))
@ -342,12 +345,11 @@
;; NIL → ALIST ;; NIL → ALIST
(defun version/deps () (defun version/deps ()
"Return info about dependencies used for build; "Return info about dependencies used for build; I.E., Go version, OS, etc.
I.E., Go version, OS, etc.
/ipns/docs.ipfs.io/reference/api/http/#api-v0-version" /ipns/docs.ipfs.io/reference/api/http/#api-v0-version"
(bind-api-result (bind-api-alist
(ipfs-call "version/deps" '()) (ipfs-call "version/deps" '())
(re-hash-table-alist result))) result))
@ -363,18 +365,16 @@
;; VARYING → BOOLEAN ;; VARYING → BOOLEAN
(defun pure-cons-p (item) (defun pure-cons-p (item)
"Return whether or not an item is 'purely' a cons-pair; "Return whether or not an item is 'purely' a cons-pair; that is, it isn't of
that is, it doesn't make up a larger list. In these cases, a larger list. In these cases, #'consp passes, but #'length errors out."
#'consp passes, but #'length errors out."
(and (consp item) (and (consp item)
(error-p (length item)))) (error-p (length item))))
;; FUNCTION FUNCTION LIST/VARYING → LIST ;; FUNCTION FUNCTION LIST/VARYING → LIST
(defun test-apply (test function data) (defun test-apply (test function data)
"Apply a given function to all items within a list that "Apply a given function to all items within a list that pass the given test,
pass the given test, recursively. AKA, if the given function recursively. AKA, if the given function returns another list, the process is
returns another list, the process is applied to that list as applied to that list as well. So on and so forth."
well. So on and so forth."
(cond ((pure-cons-p data) (cond ((pure-cons-p data)
(test-apply test function (test-apply test function
`(,(car data) ,(cdr data)))) `(,(car data) ,(cdr data))))
@ -394,9 +394,8 @@
;; HASH-TABLE → ALIST ;; HASH-TABLE → ALIST
(defun re-hash-table-alist (hash-table) (defun re-hash-table-alist (hash-table)
"Turn a hash-table into an associative list, recursively-- "Turn a hash-table into an associative list, recursively-- if any of the
if any of the hash-table's values are ther hash-tables, hash-table's values are ther hash-tables, they too are turned into alists."
they too are turned into alists."
(test-apply #'hash-table-p (test-apply #'hash-table-p
#'alexandria:hash-table-alist #'alexandria:hash-table-alist
(alexandria:hash-table-alist hash-table))) (alexandria:hash-table-alist hash-table)))