add view command and color test
This commit is contained in:
parent
7ab8f97e3e
commit
589e48304f
3 changed files with 36 additions and 3 deletions
|
|
@ -14,8 +14,13 @@
|
|||
selected-item (:item (first (filter #(= (:value %) selected-value) l)))]
|
||||
selected-item))
|
||||
|
||||
;; (defn print [text]
|
||||
;; (shell (format "gum style --foreground 212 %s" text)))
|
||||
(defn color-print
|
||||
([text] (color-print text "5"))
|
||||
([text color]
|
||||
(shell (format "gum style --foreground %s \"%s\"" color text))))
|
||||
|
||||
(defn print-markdown [text]
|
||||
(shell (format "gum format \"%s\"" text)))
|
||||
|
||||
(defn prompt-for [placeholder]
|
||||
(str/trim (-> (shell {:out :string} (format "gum input --placeholder='%s'" placeholder)) :out)))
|
||||
|
|
|
|||
|
|
@ -2,11 +2,19 @@
|
|||
(:require
|
||||
[cli-cms.create :as create]
|
||||
[cli-cms.edit :as edit]
|
||||
[cli-cms.delete :as delete]))
|
||||
[cli-cms.delete :as delete]
|
||||
[cli-cms.cli-utils :as utils]
|
||||
[cli-cms.view :as view]))
|
||||
|
||||
(defn color-test []
|
||||
(doseq [color (range 0 255)]
|
||||
(utils/color-print (str "COLOR --- " color) (str color))))
|
||||
|
||||
(defn -main [& args]
|
||||
(case (first args)
|
||||
"create" (create/run)
|
||||
"delete" (delete/run)
|
||||
"edit" (edit/run)
|
||||
"view" (view/run)
|
||||
"color-test" (color-test)
|
||||
(println "Missing command. Try create, edit, or delete.")))
|
||||
|
|
|
|||
20
src/cli_cms/view.clj
Normal file
20
src/cli_cms/view.clj
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
(ns cli-cms.view
|
||||
(:require
|
||||
[babashka.http-client :as http]
|
||||
[clojure.pprint :refer [pprint]]
|
||||
[cli-cms.config :refer [config]]
|
||||
[cheshire.core :as json]
|
||||
[clojure.string :as str]
|
||||
[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 run []
|
||||
(let [snippet-to-view (utils/select (map #(hash-map :value (:slug %) :item %) (fetch-snippets)))]
|
||||
(utils/color-print (str "title: " (:title snippet-to-view)) "4")
|
||||
(utils/color-print (str "slug: " (:slug snippet-to-view)) "4")
|
||||
(utils/color-print (str "tags: " (str/join ", " (:tags snippet-to-view))) "4")
|
||||
(utils/color-print "markdown: " "4")
|
||||
(utils/print-markdown (:markdown snippet-to-view))))
|
||||
Loading…
Add table
Add a link
Reference in a new issue