Skip to content

Expose the analyzer as a Clojure CLI tool #44

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 7, 2022
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
35 changes: 35 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,41 @@ clojure -M -m cljdoc-analyzer.main analyze \

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

=== use as a Clojure CLI tool

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:

[source,bash,no-wrap]
----
clojure -Ttools install io.github.cljdoc/cljdoc-analyzer '{:git/tag "0.10.3"}' :as cljdoc
----

and then you can invoke it in one of the supported ways.

.Analyze a library from a (local) Maven repo
[source,bash,no-wrap]
----
clojure -Tcljdoc analyze \
:project '"io.aviso/pretty"' :version '"0.1.29"' \
# Alt.1.: Download the jar, pom from a maven repo and derive the paths: \
:download true \
# Alt.2.: Provide paths to the project artifacts manually: \
#:jarpath "/path/to/project.jar" \
#:pompath "/path/to/project.pom" \
:extra-repo '["clojars https://repo.clojars.org/"]'
----

See `cljdoc-analyzer.main/analyze` for accepted configuration.

.Analyze a deps-based library in the current directory
[source,bash,no-wrap]
----
cd git clone git@github.com:fulcrologic/fulcro.git
cd fulcro
clojure -Tcljdoc analyze-local
# provided ./pom.xml and ./target/*.jar exist
----

=== logging

If using cljdoc-analyzer as a library, provide your own logging config as appropriate for your app.
Expand Down
4 changes: 3 additions & 1 deletion deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
ch.qos.logback/logback-classic {:mvn/version "1.3.0-alpha12"}
org.jsoup/jsoup {:mvn/version "1.14.3"}
version-clj/version-clj {:mvn/version "2.0.2"}
cli-matic/cli-matic {:mvn/version "0.4.3"}}
cli-matic/cli-matic {:mvn/version "0.4.3"}
babashka/fs {:mvn/version "0.1.2"}}
:tools/usage {:ns-default cljdoc-analyzer.deps-tool}
:aliases {:test
{:extra-paths ["test/unit" "test/integration" "test-resources"]
:extra-deps {lambdaisland/kaocha {:mvn/version "1.60.977"}
Expand Down
51 changes: 51 additions & 0 deletions src/cljdoc_analyzer/deps_tool.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
(ns ^:no-doc cljdoc-analyzer.deps-tool
"Entry point for running as a Clojure CLI tool"
(:require [babashka.fs :as fs]
[clojure.string :as string]
[clojure.pprint :as pp]
[clojure.tools.logging :as log]
[cljdoc-analyzer.deps :as deps]
[cljdoc-analyzer.runner :as runner]
[cljdoc-analyzer.config :as config]))

(defn- extra-repo-arg-to-option [extra-repos]
(reduce (fn [acc n]
(let [[id url] (string/split n #" ")]
(assoc acc id {:url url})))
{}
extra-repos))

(defn maybe-download [{:keys [download extra-repos project version]}]
(when download
(deps/resolve-dep
(symbol project) version
(:repos (config/load))
(extra-repo-arg-to-option extra-repos))))

(defn analyze
[{:keys [project version jarpath pompath extra-repos output-filename] :as args}]
(let [_ (log/info (str "args:\n" (with-out-str (pp/pprint args))))
{:keys [jar pom]} (maybe-download args)
{:keys [analysis-status]} (runner/analyze!
(merge
(maybe-download args)
{:project project
:version version
:jarpath (or jarpath jar)
:pompath (or pompath pom)
:extra-repos extra-repos
:namespaces :all
:exclude-with [:no-doc :skip-wiki]
:output-filename (or output-filename
(str "output-" project "-" version ".edn"))}))]
(shutdown-agents)
(System/exit (if (= :success analysis-status) 0 1))))

(defn analyze-local [_]
(let [jars (fs/list-dir "target" "*.jar")
jar (-> jars first str)]
(assert (= 1 (count jars)) "Expected to find exactly 1 target/*.jar file")
(analyze {:project (System/getProperty "user.dir")
:version "snapshot"
:pompath "pom.xml"
:jarpath jar})))
4 changes: 3 additions & 1 deletion src/cljdoc_analyzer/main.clj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
(let [config (config/load)
extra-repos (extra-repo-arg-to-option extra-repo)
{:keys [jar pom]} (deps/resolve-dep (symbol project) version (:repos config) extra-repos)]
(runner/analyze! (-> (select-keys args [:project :version :exclude-with :output-filename])
(runner/analyze! (-> (merge
{:exclude-with [:no-doc :skip-wiki]}
(select-keys args [:project :version :exclude-with :output-filename]))
(assoc :jarpath jar :pompath pom :extra-repos extra-repos)))))

(spec/def ::extra-repo
Expand Down