restructure modules
This commit is contained in:
parent
48dcb9c5a5
commit
314c480c41
12 changed files with 80 additions and 106 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/env bb
|
#!/usr/bin/env bb
|
||||||
|
|
||||||
(ns snippets-cms
|
(ns snippets-cms
|
||||||
(:require [cli.main]))
|
(:require [snippets-cms.tui]))
|
||||||
|
|
||||||
(when (= *file* (System/getProperty "babashka.file"))
|
(when (= *file* (System/getProperty "babashka.file"))
|
||||||
(apply cli.main/-main *command-line-args*))
|
(apply snippets-cms.tui/-main *command-line-args*))
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/env bb
|
#!/usr/bin/env bb
|
||||||
|
|
||||||
(ns snippets-mcp
|
(ns snippets-mcp
|
||||||
(:require [cli.mcp]))
|
(:require [snippets-cms.mcp]))
|
||||||
|
|
||||||
(when (= *file* (System/getProperty "babashka.file"))
|
(when (= *file* (System/getProperty "babashka.file"))
|
||||||
(apply cli.mcp/-main *command-line-args*))
|
(apply snippets-cms.mcp/-main *command-line-args*))
|
||||||
|
|
|
||||||
|
|
@ -1,18 +0,0 @@
|
||||||
(ns cli.delete
|
|
||||||
(:require
|
|
||||||
[com.travisshears.gum-utils :as utils]
|
|
||||||
[cli.config :refer [config]]
|
|
||||||
[clojure.pprint :refer [pprint]]
|
|
||||||
[babashka.http-client :as http]
|
|
||||||
[cheshire.core :as json]))
|
|
||||||
|
|
||||||
(defn fetch-snippets []
|
|
||||||
(let [res (http/get (str (:backend-host config) "/api/snippets?limit=25"))]
|
|
||||||
(json/parse-string (:body res) true)))
|
|
||||||
|
|
||||||
(defn delete-snippet [id]
|
|
||||||
(http/delete (str (:backend-host config) "/api/snippet") {:query-params {"id" id}}))
|
|
||||||
|
|
||||||
(defn run []
|
|
||||||
(let [selected-snippet (utils/select (map #(hash-map :value (:slug %) :item %) (fetch-snippets)))]
|
|
||||||
(delete-snippet (:id selected-snippet))))
|
|
||||||
|
|
@ -1,27 +0,0 @@
|
||||||
(ns cli.view
|
|
||||||
(:require
|
|
||||||
[babashka.http-client :as http]
|
|
||||||
[clojure.pprint :refer [pprint]]
|
|
||||||
[cli.config :refer [config]]
|
|
||||||
[cheshire.core :as json]
|
|
||||||
[clojure.string :as str]
|
|
||||||
[com.travisshears.gum-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 view [snippet]
|
|
||||||
(utils/color-print (str "title: " (:title snippet)) "4")
|
|
||||||
(utils/color-print (str "slug: " (:slug snippet)) "4")
|
|
||||||
(utils/color-print (str "tags: " (str/join ", " (:tags snippet))) "4")
|
|
||||||
(utils/color-print "markdown: " "4")
|
|
||||||
(utils/print-markdown (:markdown snippet)))
|
|
||||||
|
|
||||||
(defn run []
|
|
||||||
(let [snippet-to-view (utils/select (map #(hash-map :value (:slug %) :item %) (fetch-snippets)))]
|
|
||||||
(view (fetch-snippet (:id snippet-to-view)))))
|
|
||||||
32
src/snippets_cms/backend_connect.clj
Normal file
32
src/snippets_cms/backend_connect.clj
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
(ns snippets-cms.backend-connect
|
||||||
|
(:require
|
||||||
|
[clojure.edn :as edn]
|
||||||
|
[babashka.http-client :as http]
|
||||||
|
[snippets-cms.config :refer [config]]))
|
||||||
|
|
||||||
|
(defn- get-request [path params]
|
||||||
|
(let [res (http/get (str (:backend-host config) path)
|
||||||
|
{:headers {"Accept" "application/edn"}
|
||||||
|
:query-params params})]
|
||||||
|
(edn/read-string (:body res))))
|
||||||
|
|
||||||
|
(defn fetch-snippets [& [limit]]
|
||||||
|
(let [params (if limit {:limit limit} {})]
|
||||||
|
(get-request "/api/snippets" params)))
|
||||||
|
|
||||||
|
(defn fetch-snippet [id]
|
||||||
|
(get-request "/api/snippet" {:id id}))
|
||||||
|
|
||||||
|
(defn delete-snippet [id]
|
||||||
|
(http/delete (str (:backend-host config) "/api/snippet") {:query-params {"id" id}}))
|
||||||
|
|
||||||
|
(defn update-snippet [id patch]
|
||||||
|
(http/patch (str (:backend-host config) "/api/snippet")
|
||||||
|
{:query-params {:id id}
|
||||||
|
:headers {:content-type "application/edn"}
|
||||||
|
:body (pr-str patch)}))
|
||||||
|
|
||||||
|
(defn create-snippet [{:keys [title slug markdown tags]}]
|
||||||
|
(http/post (str (:backend-host config) "/api/snippet")
|
||||||
|
{:headers {:content-type "application/edn"}
|
||||||
|
:body (pr-str {:title title :slug slug :markdown markdown :tags tags})}))
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
(ns cli.config
|
(ns snippets-cms.config
|
||||||
(:require
|
(:require
|
||||||
[babashka.fs :as fs]
|
[babashka.fs :as fs]
|
||||||
[clojure.string :as str]))
|
[clojure.string :as str]))
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
(ns cli.mcp
|
(ns snippets-cms.mcp
|
||||||
(:require
|
(:require
|
||||||
[babashka.http-client :as http]
|
[cheshire.core :as json]
|
||||||
[cli.config :refer [config]]
|
[snippets-cms.backend-connect :refer [create-snippet
|
||||||
[clojure.edn :as edn]
|
fetch-snippet
|
||||||
[cheshire.core :as json]))
|
fetch-snippets]]))
|
||||||
|
|
||||||
;; Tool definitions
|
;; Tool definitions
|
||||||
(def available-tools
|
(def available-tools
|
||||||
|
|
@ -32,22 +32,6 @@
|
||||||
:description "Array of tags for categorizing the snippet"}}
|
:description "Array of tags for categorizing the snippet"}}
|
||||||
:required ["title" "slug" "markdown" "tags"]}}])
|
:required ["title" "slug" "markdown" "tags"]}}])
|
||||||
|
|
||||||
;; interact with backend api
|
|
||||||
(defn fetch-snippets []
|
|
||||||
(let [res (http/get (str (:backend-host config) "/api/snippets"))]
|
|
||||||
(json/parse-string (:body res) true)))
|
|
||||||
|
|
||||||
(defn fetch-snippet [id]
|
|
||||||
(let [res (http/get (str (:backend-host config) "/api/snippet")
|
|
||||||
{:headers {"Accept" "application/edn"}
|
|
||||||
:query-params {:id id}})]
|
|
||||||
(edn/read-string (:body res))))
|
|
||||||
|
|
||||||
(defn create-snippet [{:keys [title slug markdown tags]}]
|
|
||||||
(http/post (str (:backend-host config) "/api/snippet")
|
|
||||||
{:headers {:content-type "application/edn"}
|
|
||||||
:body (pr-str {:title title :slug slug :markdown markdown :tags tags})}))
|
|
||||||
|
|
||||||
;; Tool implementations
|
;; Tool implementations
|
||||||
(defn mcp-res [fn args]
|
(defn mcp-res [fn args]
|
||||||
(try
|
(try
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
(ns cli.main
|
(ns snippets-cms.tui
|
||||||
(:require
|
(:require
|
||||||
[cli.create :as create]
|
[snippets-cms.tui-actions.create :as create]
|
||||||
[cli.edit :as edit]
|
[snippets-cms.tui-actions.edit :as edit]
|
||||||
[cli.delete :as delete]
|
[snippets-cms.tui-actions.delete :as delete]
|
||||||
[com.travisshears.gum-utils :as utils]
|
[com.travisshears.gum-utils :as utils]
|
||||||
[cli.view :as view]))
|
[snippets-cms.tui-actions.view :as view]))
|
||||||
|
|
||||||
(defn color-test []
|
(defn color-test []
|
||||||
(doseq [color (range 0 255)]
|
(doseq [color (range 0 255)]
|
||||||
|
|
@ -1,16 +1,7 @@
|
||||||
(ns cli.create
|
(ns snippets-cms.tui-actions.create
|
||||||
(:require
|
(:require
|
||||||
[com.travisshears.gum-utils :as utils]
|
[com.travisshears.gum-utils :as utils]
|
||||||
[clojure.string :as str]
|
[snippets-cms.backend-connect :refer [create-snippet]]))
|
||||||
[cli.config :refer [config]]
|
|
||||||
[babashka.http-client :as http]
|
|
||||||
[cheshire.core :as json]
|
|
||||||
[babashka.process :refer [shell]]))
|
|
||||||
|
|
||||||
(defn create-snippet [{: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 run []
|
(defn run []
|
||||||
(let [title (utils/prompt-for "title")
|
(let [title (utils/prompt-for "title")
|
||||||
8
src/snippets_cms/tui_actions/delete.clj
Normal file
8
src/snippets_cms/tui_actions/delete.clj
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
(ns snippets-cms.tui-actions.delete
|
||||||
|
(:require
|
||||||
|
[com.travisshears.gum-utils :as utils]
|
||||||
|
[snippets-cms.backend-connect :refer [delete-snippet fetch-snippets]]))
|
||||||
|
|
||||||
|
(defn run []
|
||||||
|
(let [selected-snippet (utils/select (map #(hash-map :value (:slug %) :item %) (fetch-snippets)))]
|
||||||
|
(delete-snippet (:id selected-snippet))))
|
||||||
|
|
@ -1,15 +1,9 @@
|
||||||
(ns cli.edit
|
(ns snippets-cms.tui-actions.edit
|
||||||
(:require
|
(:require
|
||||||
[babashka.http-client :as http]
|
[com.travisshears.gum-utils :as utils]
|
||||||
[clojure.pprint :refer [pprint]]
|
[snippets-cms.backend-connect :refer [fetch-snippet fetch-snippets
|
||||||
[cli.config :refer [config]]
|
update-snippet]]
|
||||||
[cli.view :as view]
|
[snippets-cms.tui-actions.view :as view]))
|
||||||
[cheshire.core :as json]
|
|
||||||
[com.travisshears.gum-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 prompt-for-edit-type []
|
(defn prompt-for-edit-type []
|
||||||
(utils/select (map #(hash-map :value (name %) :item %) '(:title
|
(utils/select (map #(hash-map :value (name %) :item %) '(:title
|
||||||
|
|
@ -19,12 +13,6 @@
|
||||||
:add-tags
|
:add-tags
|
||||||
:done))))
|
:done))))
|
||||||
|
|
||||||
(defn send-patch [id patch]
|
|
||||||
(http/patch (str (:backend-host config) "/api/snippet")
|
|
||||||
{:query-params {:id id}
|
|
||||||
:headers {:content-type "application/json"}
|
|
||||||
:body (json/encode patch)}))
|
|
||||||
|
|
||||||
(defn edit
|
(defn edit
|
||||||
([snippet]
|
([snippet]
|
||||||
(edit snippet {}))
|
(edit snippet {}))
|
||||||
|
|
@ -46,6 +34,6 @@
|
||||||
|
|
||||||
(defn run []
|
(defn run []
|
||||||
(let [snippet-to-edit (utils/select (map #(hash-map :value (:slug %) :item %) (fetch-snippets)))]
|
(let [snippet-to-edit (utils/select (map #(hash-map :value (:slug %) :item %) (fetch-snippets)))]
|
||||||
(send-patch (:id snippet-to-edit) (edit snippet-to-edit))
|
(update-snippet (:id snippet-to-edit) (edit snippet-to-edit))
|
||||||
(println "Snippet updated successfully")
|
(println "Snippet updated successfully")
|
||||||
(view/view (view/fetch-snippet (:id snippet-to-edit)))))
|
(view/view (fetch-snippet (:id snippet-to-edit)))))
|
||||||
16
src/snippets_cms/tui_actions/view.clj
Normal file
16
src/snippets_cms/tui_actions/view.clj
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
(ns snippets-cms.tui-actions.view
|
||||||
|
(:require
|
||||||
|
[clojure.string :as str]
|
||||||
|
[com.travisshears.gum-utils :as utils]
|
||||||
|
[snippets-cms.backend-connect :refer [fetch-snippet fetch-snippets]]))
|
||||||
|
|
||||||
|
(defn view [snippet]
|
||||||
|
(utils/color-print (str "title: " (:title snippet)) "4")
|
||||||
|
(utils/color-print (str "slug: " (:slug snippet)) "4")
|
||||||
|
(utils/color-print (str "tags: " (str/join ", " (:tags snippet))) "4")
|
||||||
|
(utils/color-print "markdown: " "4")
|
||||||
|
(utils/print-markdown (:markdown snippet)))
|
||||||
|
|
||||||
|
(defn run []
|
||||||
|
(let [snippet-to-view (utils/select (map #(hash-map :value (:slug %) :item %) (fetch-snippets 25)))]
|
||||||
|
(view (fetch-snippet (:id snippet-to-view)))))
|
||||||
Loading…
Add table
Add a link
Reference in a new issue