Search maven artifacts with a babashka script

Since Maven Central changed the search I had to fix my helper script. Time to try out Babashka.

#!/usr/bin/env bb
(require '[cheshire.core :as json])

(defn artifact [{:keys [g a latestVersion]}]
  (str g ":" a ":" latestVersion))

(defn query [q]
  (if (str/includes? q ":")
    (let [[g a] (str/split q #":" 2)]
      (str "g%3a" g "%20AND%20" "a%3a" a))
    q))

(defn request [q]
  (-> (org.httpkit.client/get
        (str "http://search.maven.org/solrsearch/select?rows=50&q=" (query q))
        {:content-type "application/json"})
      deref
      :body
      (json/parse-string true)
      :response
      :docs))

(assert (= 1 (count *command-line-args*)))

(->>
  *command-line-args*
  first
  request
  (map artifact)
  (run! prn))