Search Maven artifacts with Babashka

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 v latestVersion]}]
  (str g ":" a ":" (or v latestVersion)))

(defn query [q]
  (let [query-params {:start 0 :rows 50}]
    (if (str/includes? q ":")
      (let [[g a] (str/split q #":" 2)]
        (assoc query-params 
           :q (str "g:" g " AND " "a:" a)
               :core "gav"))
      (assoc query-params :q q))))

(defn request [q]
  (-> (org.httpkit.client/get
        "https://search.maven.org/solrsearch/select"
        {:content-type "application/json"
         :query-params (query q)})
      deref
      :body
      (json/parse-string true)
      :response
      :docs))

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

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