diff --git a/README.adoc b/README.adoc index 591deac..9331536 100644 --- a/README.adoc +++ b/README.adoc @@ -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. diff --git a/deps.edn b/deps.edn index 45012e6..3f3c991 100644 --- a/deps.edn +++ b/deps.edn @@ -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"} diff --git a/src/cljdoc_analyzer/deps_tool.clj b/src/cljdoc_analyzer/deps_tool.clj new file mode 100644 index 0000000..e3da0df --- /dev/null +++ b/src/cljdoc_analyzer/deps_tool.clj @@ -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}))) \ No newline at end of file diff --git a/src/cljdoc_analyzer/main.clj b/src/cljdoc_analyzer/main.clj index 08036d6..eda1d58 100644 --- a/src/cljdoc_analyzer/main.clj +++ b/src/cljdoc_analyzer/main.clj @@ -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