Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/clojure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Install clojure tools
uses: DeLaGuardo/setup-clojure@13.4
with:
cli: 1.12.2.1565
cli: 1.12.3.1577

- name: Cache clojure dependencies
uses: actions/cache@v4
Expand Down
6 changes: 3 additions & 3 deletions deps.edn
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{:paths ["src"
"resources"]

:deps {org.clj-commons/pretty {:mvn/version "3.6.4"}
:deps {org.clj-commons/pretty {:mvn/version "3.6.5"}
org.clj-commons/humanize {:mvn/version "1.1"}}

:net.lewisship.build/scm
Expand All @@ -15,7 +15,7 @@
:extra-deps {io.github.cognitect-labs/test-runner {:git/tag "v0.5.1"
:git/sha "dfb30dd"}
io.github.hlship/trace {:mvn/version "1.4"}
io.github.tonsky/clj-reload {:mvn/version "0.9.8"}
io.github.tonsky/clj-reload {:mvn/version "1.0.0"}
nubank/matcher-combinators {:mvn/version "3.9.2"}
babashka/babashka {:mvn/version "1.12.208"}}
:exec-fn cognitect.test-runner.api/test
Expand All @@ -34,7 +34,7 @@
{:override-deps {org.clojure/clojure ^:antq/exclude {:mvn/version "1.11.4"}}}

:lint
{:deps {clj-kondo/clj-kondo {:mvn/version "2025.07.28"}}
{:deps {clj-kondo/clj-kondo {:mvn/version "2025.09.22"}}
:main-opts ["-m" "clj-kondo.main" "--lint" "src" "test"]}

:build
Expand Down
36 changes: 20 additions & 16 deletions src/net/lewisship/cli_tools.clj
Original file line number Diff line number Diff line change
Expand Up @@ -201,22 +201,26 @@
"Expand dispatch options into tool options, leveraging a cache."
[options]
(let [{:keys [tool-name cache-dir cache-digest]} options
cache-dir' (when cache-dir
(fs/expand-home cache-dir))
digest (when cache-dir'
(or cache-digest
(cache/classpath-digest options)))
cached (when digest
(cache/read-from-cache cache-dir' tool-name digest))
result (if cached
cached
(let [expanded (impl/expand-tool-options options)]
(when cache-dir'
(cache/write-to-cache cache-dir' tool-name digest expanded))
expanded))]
(merge result
{:cache-digest digest}
(select-keys options [:tool-name :doc :arguments :tool-summary :pre-dispatch]))))
tool-name' (or tool-name
(impl/default-tool-name)
(throw (ex-info "No :tool-name specified" {:options options})))
cache-dir' (when cache-dir
(fs/expand-home cache-dir))
digest (when cache-dir'
(or cache-digest
(cache/classpath-digest options)))
cached-command-root (when digest
(cache/read-from-cache cache-dir' tool-name' digest))
command-root (if cached-command-root
cached-command-root
(let [built-command-root (impl/build-command-root tool-name' options)]
(when cache-dir'
(cache/write-to-cache cache-dir' tool-name' digest built-command-root))
built-command-root))]
(merge {:tool-name tool-name'
:cache-digest digest
:command-root command-root}
(select-keys options [:doc :arguments :tool-summary :pre-dispatch]))))

(defn- dispatch*
"Called (indirectly/anonymously) from a tool handler to process remaining command line arguments."
Expand Down
25 changes: 10 additions & 15 deletions src/net/lewisship/cli_tools/impl.clj
Original file line number Diff line number Diff line change
Expand Up @@ -959,7 +959,7 @@
(and (= 1 (count arguments))
(-> arguments first map?)))

(defn- default-tool-name
(defn default-tool-name
[]
(when-let [path (System/getProperty "babashka.file")]
(-> path io/file .getName)))
Expand Down Expand Up @@ -1042,18 +1042,13 @@
; groups have just :group-doc, no :title
doc' (assoc :group-doc doc'))))

(defn expand-tool-options
[dispatch-options]
(let [{:keys [tool-name transformer]} dispatch-options
tool-name' (or tool-name
(default-tool-name)
(throw (ex-info "No :tool-name specified" {:options dispatch-options})))
(defn build-command-root
[tool-name dispatch-options]
(let [{:keys [transformer]} dispatch-options
;; options are also the root descriptor for the built-in namespace
root (-> dispatch-options
(update :namespaces conj 'net.lewisship.cli-tools.builtins)
(build-command-group nil tool-name)
:subs)
root' (cond->> root
transformer (transformer dispatch-options))]
{:tool-name tool-name'
:command-root root'}))
root (-> dispatch-options
(update :namespaces conj 'net.lewisship.cli-tools.builtins)
(build-command-group nil tool-name)
:subs)]
(cond->> root
transformer (transformer dispatch-options))))