一键导入
cli
Build CLI tools using Babashka and babashka.cli. Scaffolds new CLIs as standalone bins or multi-command tools following project conventions.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Build CLI tools using Babashka and babashka.cli. Scaffolds new CLIs as standalone bins or multi-command tools following project conventions.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
| name | cli |
| description | Build CLI tools using Babashka and babashka.cli. Scaffolds new CLIs as standalone bins or multi-command tools following project conventions. |
Build Babashka CLI tools that follow this project's conventions. There are two patterns depending on complexity.
For tools with one job (like browser, image_to_text). Lives in src/bins/ with a shell wrapper in bin/.
src/bins/<name>.clj # Implementation with -main
bin/<name> # Shell wrapper
bin/<name>)#!/usr/bin/env bash
set -euo pipefail
exec bb --config "$HOME/Code/My/bb.edn" -m bins.<name> "$@"
Make executable: chmod +x bin/<name>
src/bins/<name>.clj)(ns bins.<name>
(:require [babashka.process :refer [shell]]))
(defn -main [& args]
;; implementation
)
For tools with subcommands, options, and help text. Gets its own namespace tree under src/<name>/.
src/<name>/
core.clj # Entry point, dispatch
table.clj # Help generation, dispatch (copy from template)
commands/
<command>.clj # One file per command group
bin/<name> # Shell wrapper
bin/<name>)#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
exec bb --config "$PROJECT_ROOT/bb.edn" -m <name>.core "$@"
src/<name>/core.clj)(ns <name>.core
(:require [babashka.cli :as cli]
[<name>.table :as table]
[<name>.commands.<cmd> :refer [<cmd>-cmd]]))
(def cli-config
{:name "<name>"
:description "What this tool does"
:usage "<name> [options] <args>"
:commands [{:name "<cmd>"
:description "Description"}
{:name "help"
:description "Show help"}]
:options [{:flags ["-f" "--flag"]
:description "A boolean flag"}
{:flags ["-o" "--option"]
:description "An option with value"}]})
(def cli-spec
{:flag {:alias :f :desc "A boolean flag"}
:option {:alias :o :desc "An option"}
:help {:alias :h :desc "Show help"}})
(defn help-cmd [_]
(table/print-help cli-config))
(def command-table
{"help" help-cmd
:default <cmd>-cmd})
(defn -main [& args]
(let [parsed (cli/parse-args args {:spec cli-spec})
opts (:opts parsed)
rest-args (:args parsed)]
(cond
(:help opts) (help-cmd nil)
(empty? rest-args) (do (help-cmd nil) (System/exit 1))
:else (table/dispatch command-table rest-args opts))))
src/<name>/table.clj)Copy from ressources/templates/cli-template/src/cli/table.clj or src/scdl/table.clj.
src/<name>/commands/<cmd>.clj)(ns <name>.commands.<cmd>
(:require [babashka.process :refer [shell]]))
(defn <cmd>-cmd
"Description of what this command does."
[{:keys [opts rest-args]}]
(let [arg (first rest-args)]
(when (nil? arg)
(println "Error: argument required")
(System/exit 1))
;; implementation
))
For CLIs that need nested subcommands (like the main my CLI), use the dispatch table pattern from ressources/templates/cli-template/:
(def table
[{:cmds ["subcmd"]
:fn subcmd-fn
:desc "Description"
:args->opts [:arg1] ; positional args mapped to opt keys
:coerce {:port :long
:verbose :boolean}
:alias {:p :port :v :verbose}
:examples ["mycli subcmd arg"]}])
Type coercion options: :long, :double, :boolean, :keyword, :symbol, :edn, [] (vector), #{} (set).
These are already available - no need to add them:
babashka.cli - CLI argument parsingbabashka.process - Shell/subprocess (shell, process)babashka.fs - Filesystem operationscheshire.core - JSON parsingclojure.string - String utilitiesclojure.java.io - IO-cmd suffix: download-cmd, hello-cmd(comment ...) block at bottom for REPL testingSystem/exit 1 for error exitsbabashka.process/shell for subprocesses (inherits stdio)defn- (private)~ paths with (str (System/getProperty "user.home") (subs path 1))bin/<name> shell wrapperchmod +x bin/<name>bb --config bb.edn -m <namespace> <args>Build Babashka HTTP API servers using httpkit, ruuter, and hiccup. Scaffolds server projects with routing, handlers, rendering, WebSocket support, and HTMX integration.
Create changelog
Create docs
Build fullstack apps with Squint + Eucalypt frontend and Babashka + Ruuter backend. Scaffolds projects with reactive UI, JSON API, CORS, dev server, and Vite single-file builds.
create a pr description
Generates readmes for humans
基于 SOC 职业分类