Skip to content

Commit cb5e260

Browse files
committed
Expose the analyzer as a Clojure CLI tool
so that users can easily verify that their libraries workf fine with cljdoc
1 parent 2585e4c commit cb5e260

File tree

4 files changed

+93
-2
lines changed

4 files changed

+93
-2
lines changed

README.adoc

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,41 @@ clojure -M -m cljdoc-analyzer.main analyze \
162162

163163
We can look at other features as we get a feel for what folks are interested in.
164164

165+
=== use as a Clojure CLI tool
166+
167+
You can also install and use cljdoc-analyzer as a https://clojure.org/reference/deps_and_cli#tool_install[Clojure CLI Tool]. First you need to install it:
168+
169+
[source,bash,no-wrap]
170+
----
171+
clojure -Ttools install io.github.cljdoc/cljdoc-analyzer '{:git/tag "0.10.3"}' :as cljdoc
172+
----
173+
174+
and then you can invoke it in one of the supported ways.
175+
176+
.Analyze a library from a (local) Maven repo
177+
[source,bash,no-wrap]
178+
----
179+
clojure -Tcljdoc analyze \
180+
:project '"io.aviso/pretty"' :version '"0.1.29"' \
181+
# Alt.1.: Download the jar, pom from a maven repo and derive the paths: \
182+
:download true \
183+
# Alt.2.: Provide paths to the project artifacts manually: \
184+
#:jarpath "/path/to/project.jar" \
185+
#:pompath "/path/to/project.pom" \
186+
:extra-repo '["clojars https://repo.clojars.org/"]'
187+
----
188+
189+
See `cljdoc-analyzer.main/analyze` for accepted configuration.
190+
191+
.Analyze a deps-based library in the current directory
192+
[source,bash,no-wrap]
193+
----
194+
cd git clone [email protected]:fulcrologic/fulcro.git
195+
cd fulcro
196+
clojure -Tcljdoc analyze-local
197+
# provided ./pom.xml and ./target/*.jar exist
198+
----
199+
165200
=== logging
166201

167202
If using cljdoc-analyzer as a library, provide your own logging config as appropriate for your app.

deps.edn

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
ch.qos.logback/logback-classic {:mvn/version "1.3.0-alpha12"}
66
org.jsoup/jsoup {:mvn/version "1.14.3"}
77
version-clj/version-clj {:mvn/version "2.0.2"}
8-
cli-matic/cli-matic {:mvn/version "0.4.3"}}
8+
cli-matic/cli-matic {:mvn/version "0.4.3"}
9+
babashka/fs {:mvn/version "0.1.2"}}
10+
:tools/usage {:ns-default cljdoc-analyzer.deps-tool}
911
:aliases {:test
1012
{:extra-paths ["test/unit" "test/integration" "test-resources"]
1113
:extra-deps {lambdaisland/kaocha {:mvn/version "1.60.977"}

src/cljdoc_analyzer/deps_tool.clj

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
(ns ^:no-doc cljdoc-analyzer.deps-tool
2+
"Entry point for running as a Clojure CLI tool"
3+
(:require [babashka.fs :as fs]
4+
[clojure.set :as set]
5+
[clojure.string :as string]
6+
[clojure.pprint :as pp]
7+
[clojure.tools.logging :as log]
8+
[cljdoc-analyzer.deps :as deps]
9+
[cljdoc-analyzer.runner :as runner]
10+
[cljdoc-analyzer.config :as config]))
11+
12+
(defn- extra-repo-arg-to-option [extra-repos]
13+
(reduce (fn [acc n]
14+
(let [[id url] (string/split n #" ")]
15+
(assoc acc id {:url url})))
16+
{}
17+
extra-repos))
18+
19+
(defn maybe-download [{:keys [download extra-repos project version]}]
20+
(when download
21+
(deps/resolve-dep
22+
(symbol project) version
23+
(:repos (config/load))
24+
(extra-repo-arg-to-option extra-repos))))
25+
26+
(defn analyze
27+
[{:keys [project version jarpath pompath extra-repos output-filename] :as args}]
28+
(let [_ (log/info (str "args:\n" (with-out-str (pp/pprint args))))
29+
{:keys [jar pom]} (maybe-download args)
30+
{:keys [analysis-status]} (runner/analyze!
31+
(merge
32+
(maybe-download args)
33+
{:project project
34+
:version version
35+
:jarpath (or jarpath jar)
36+
:pompath (or pompath pom)
37+
:extra-repos extra-repos
38+
:namespaces :all
39+
:exclude-with [:no-doc :skip-wiki]
40+
:output-filename (or output-filename
41+
(str "output-" project "-" version ".edn"))}))]
42+
(shutdown-agents)
43+
(System/exit (if (= :success analysis-status) 0 1))))
44+
45+
(defn analyze-local [_]
46+
(let [jars (fs/list-dir "target" "*.jar")
47+
jar (-> jars first str)]
48+
(assert (= 1 (count jars)) "Expected to find exactly 1 target/*.jar file")
49+
(analyze {:project (System/getProperty "user.dir")
50+
:version "snapshot"
51+
:pompath "pom.xml"
52+
:jarpath jar})))

src/cljdoc_analyzer/main.clj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
(let [config (config/load)
1919
extra-repos (extra-repo-arg-to-option extra-repo)
2020
{:keys [jar pom]} (deps/resolve-dep (symbol project) version (:repos config) extra-repos)]
21-
(runner/analyze! (-> (select-keys args [:project :version :exclude-with :output-filename])
21+
(runner/analyze! (-> (merge
22+
{:exclude-with [:no-doc :skip-wiki]}
23+
(select-keys args [:project :version :exclude-with :output-filename]))
2224
(assoc :jarpath jar :pompath pom :extra-repos extra-repos)))))
2325

2426
(spec/def ::extra-repo

0 commit comments

Comments
 (0)