Compare commits
No commits in common. "314c480c419745780191039cb162a40d7ec5b717" and "95152a12ee709548c5e7a030dc78332effa5cb05" have entirely different histories.
314c480c41
...
95152a12ee
12 changed files with 106 additions and 80 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/env bb
|
#!/usr/bin/env bb
|
||||||
|
|
||||||
(ns snippets-cms
|
(ns snippets-cms
|
||||||
(:require [snippets-cms.tui]))
|
(:require [cli.main]))
|
||||||
|
|
||||||
(when (= *file* (System/getProperty "babashka.file"))
|
(when (= *file* (System/getProperty "babashka.file"))
|
||||||
(apply snippets-cms.tui/-main *command-line-args*))
|
(apply cli.main/-main *command-line-args*))
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/env bb
|
#!/usr/bin/env bb
|
||||||
|
|
||||||
(ns snippets-mcp
|
(ns snippets-mcp
|
||||||
(:require [snippets-cms.mcp]))
|
(:require [cli.mcp]))
|
||||||
|
|
||||||
(when (= *file* (System/getProperty "babashka.file"))
|
(when (= *file* (System/getProperty "babashka.file"))
|
||||||
(apply snippets-cms.mcp/-main *command-line-args*))
|
(apply cli.mcp/-main *command-line-args*))
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
(ns snippets-cms.config
|
(ns cli.config
|
||||||
(:require
|
(:require
|
||||||
[babashka.fs :as fs]
|
[babashka.fs :as fs]
|
||||||
[clojure.string :as str]))
|
[clojure.string :as str]))
|
||||||
|
|
@ -1,7 +1,16 @@
|
||||||
(ns snippets-cms.tui-actions.create
|
(ns cli.create
|
||||||
(:require
|
(:require
|
||||||
[com.travisshears.gum-utils :as utils]
|
[com.travisshears.gum-utils :as utils]
|
||||||
[snippets-cms.backend-connect :refer [create-snippet]]))
|
[clojure.string :as str]
|
||||||
|
[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")
|
||||||
18
src/cli/delete.clj
Normal file
18
src/cli/delete.clj
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
(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,9 +1,15 @@
|
||||||
(ns snippets-cms.tui-actions.edit
|
(ns cli.edit
|
||||||
(:require
|
(:require
|
||||||
[com.travisshears.gum-utils :as utils]
|
[babashka.http-client :as http]
|
||||||
[snippets-cms.backend-connect :refer [fetch-snippet fetch-snippets
|
[clojure.pprint :refer [pprint]]
|
||||||
update-snippet]]
|
[cli.config :refer [config]]
|
||||||
[snippets-cms.tui-actions.view :as view]))
|
[cli.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
|
||||||
|
|
@ -13,6 +19,12 @@
|
||||||
: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 {}))
|
||||||
|
|
@ -34,6 +46,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)))]
|
||||||
(update-snippet (:id snippet-to-edit) (edit snippet-to-edit))
|
(send-patch (:id snippet-to-edit) (edit snippet-to-edit))
|
||||||
(println "Snippet updated successfully")
|
(println "Snippet updated successfully")
|
||||||
(view/view (fetch-snippet (:id snippet-to-edit)))))
|
(view/view (view/fetch-snippet (:id snippet-to-edit)))))
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
(ns snippets-cms.tui
|
(ns cli.main
|
||||||
(:require
|
(:require
|
||||||
[snippets-cms.tui-actions.create :as create]
|
[cli.create :as create]
|
||||||
[snippets-cms.tui-actions.edit :as edit]
|
[cli.edit :as edit]
|
||||||
[snippets-cms.tui-actions.delete :as delete]
|
[cli.delete :as delete]
|
||||||
[com.travisshears.gum-utils :as utils]
|
[com.travisshears.gum-utils :as utils]
|
||||||
[snippets-cms.tui-actions.view :as view]))
|
[cli.view :as view]))
|
||||||
|
|
||||||
(defn color-test []
|
(defn color-test []
|
||||||
(doseq [color (range 0 255)]
|
(doseq [color (range 0 255)]
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
(ns snippets-cms.mcp
|
(ns cli.mcp
|
||||||
(:require
|
(:require
|
||||||
[cheshire.core :as json]
|
[babashka.http-client :as http]
|
||||||
[snippets-cms.backend-connect :refer [create-snippet
|
[cli.config :refer [config]]
|
||||||
fetch-snippet
|
[clojure.edn :as edn]
|
||||||
fetch-snippets]]))
|
[cheshire.core :as json]))
|
||||||
|
|
||||||
;; Tool definitions
|
;; Tool definitions
|
||||||
(def available-tools
|
(def available-tools
|
||||||
|
|
@ -32,6 +32,22 @@
|
||||||
: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?limit=2000"))]
|
||||||
|
(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
|
||||||
27
src/cli/view.clj
Normal file
27
src/cli/view.clj
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
(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)))))
|
||||||
|
|
@ -1,32 +0,0 @@
|
||||||
(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,8 +0,0 @@
|
||||||
(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,16 +0,0 @@
|
||||||
(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