get edit command started with snippet select and editing
This commit is contained in:
parent
c4ff9a86b6
commit
e71062bb87
4 changed files with 50 additions and 7 deletions
|
|
@ -1 +1,38 @@
|
|||
(ns cli-cms.edit)
|
||||
(ns cli-cms.edit
|
||||
(:require
|
||||
[babashka.http-client :as http]
|
||||
[clojure.pprint :refer [pprint]]
|
||||
[cli-cms.config :refer [config]]
|
||||
[cheshire.core :as json]
|
||||
[cli-cms.cli-utils :as utils]))
|
||||
|
||||
(defn fetch-snippets []
|
||||
(let [res (http/get (str (:backend-host config) "/api/snippets?limit=25"))]
|
||||
(json/parse-string (:body res) true)))
|
||||
|
||||
;; (defn fetch-snippet [id]
|
||||
;; (let [res (http/get (str (:backend-host config) "/api/snippet") {:query-params {"id" id}})]
|
||||
;; (json/parse-string (:body res) true)))
|
||||
(defn prompt-for-edit-type []
|
||||
(utils/select '({:value "title" :item :title}
|
||||
{:value "markdown" :item :markdown}
|
||||
{:value "slug" :item :slug}
|
||||
{:value "tags" :item :tags}
|
||||
{:value "done" :item :done})))
|
||||
|
||||
;; (defn send-patch [{:keys [title slug markdown tags]}]
|
||||
;; (http/post (str (:backend-host config) "/api/snippet")
|
||||
;; {:headers {:content-type "application/json"}
|
||||
;; :body (json/encode {:title title :slug slug :markdown markdown :tags tags})}))
|
||||
|
||||
(defn edit [snippet]
|
||||
(case (prompt-for-edit-type)
|
||||
:title (edit (assoc snippet :title (utils/prompt-for "title")))
|
||||
:slug (edit (assoc snippet :slug (utils/prompt-for "slug")))
|
||||
:tags (edit (assoc snippet :tags (utils/prompt-for-many "tags")))
|
||||
:markdown (edit (assoc snippet :markdown (utils/prompt-for-long-form "markdown")))
|
||||
:done snippet))
|
||||
|
||||
(defn run []
|
||||
(let [snippet-to-edit (utils/select (map #(hash-map :value (:slug %) :item %) (fetch-snippets)))]
|
||||
(pprint (edit snippet-to-edit))))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue