prompt for all data needed to create snippet

This commit is contained in:
Travis Shears 2025-06-07 17:51:50 +02:00
parent 4c1021cfd0
commit ad56963220
4 changed files with 54 additions and 3 deletions

7
README.md Normal file
View file

@ -0,0 +1,7 @@
## Snippets CLI CMS
A simple command-line interface for managing my code snippets.
Written in Clojure via Babashka.
Interactive elements are powered by [Gum](https://github.com/charmbracelet/gum).

27
src/cli_cms/cli_utils.clj Normal file
View file

@ -0,0 +1,27 @@
(ns cli-cms.cli-utils
(:require
[clojure.string :as str]
[babashka.process :refer [shell]]))
(defn print [text]
(shell (format "gum style --foreground 212 %s" text)))
(defn prompt-for [placeholder]
(str/trim (-> (shell {:out :string} (format "gum input --placeholder='%s'" placeholder)) :out)))
(defn prompt-for-many
([placeholder]
(let [val (prompt-for (str placeholder ", enter done to finish"))]
(println val)
(if (= val "done")
nil
(prompt-for-many placeholder '(val)))))
([placeholder carry]
(let [val (prompt-for (str placeholder ", enter done to finish"))]
(println val)
(if (= val "done")
carry
(prompt-for-many placeholder (conj carry val))))))
(defn prompt-for-long-form [placeholder]
(-> (shell {:out :string} (format "gum write --placeholder='%s'" placeholder)) :out))

View file

@ -1 +1,16 @@
(ns cli-cms.create)
(ns cli-cms.create
(:require
[cli-cms.cli-utils :as utils]
[clojure.string :as str]
[babashka.process :refer [shell]]))
(defn run []
(let [title (utils/prompt-for "title")
slug (utils/prompt-for "slug")
tags (utils/prompt-for-many "tags")
markdown (utils/prompt-for-long-form "markdown")]
;; (utils/print "Please enter a title:")
;; (println "Please enter a title:")
(println (format "TODO: create post with title: %s and slug %s" title slug))
(println tags)
(println markdown)))

View file

@ -1,8 +1,10 @@
(ns cli-cms.main
(:require [babashka.http-client :as http]))
(:require
[cli-cms.create :as create]
[babashka.http-client :as http]))
(defn -main [& args]
(case (first args)
"create" (println "TODO: implment create snippet")
"create" (create/run)
"edit" (println "TODO: implment edit snippet")
(println "Missing command. Try 'create' or 'edit'.")))