Skip to content

Instantly share code, notes, and snippets.

@tylerw
Created June 18, 2022 19:23
Show Gist options
  • Select an option

  • Save tylerw/83be543f2fb983033919fe0423a80ae8 to your computer and use it in GitHub Desktop.

Select an option

Save tylerw/83be543f2fb983033919fe0423a80ae8 to your computer and use it in GitHub Desktop.

Revisions

  1. tylerw created this gist Jun 18, 2022.
    28 changes: 28 additions & 0 deletions update-clj-tools.bb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    #!/usr/bin/env bb

    ;;;
    ; A babashka script to update all clojure -Ttools to the latest versions
    ; author: Tyler Wardhaugh
    ;;;

    (ns update-clj-tools
    (:require [babashka.fs :as fs]
    [babashka.process :refer [process]]))

    (defn install-latest
    "Install the latest version of tool by invoking clj(1) as a process."
    [tool]
    (let [base-cmd ["clj" "-Ttools" "install-latest" ":tool"]]
    @(process (conj base-cmd tool) {:out :inherit})))

    (defn -main
    "Update tools in the directory passed in (defaulting to ~/.clojure/tools)"
    [args]
    (let [raw-path (or (first args) "~/.clojure/tools")
    path (-> raw-path fs/expand-home fs/canonicalize)]
    (doseq [tool (->> (fs/list-dir path "*.edn")
    (map (comp fs/strip-ext fs/file-name)))]
    (install-latest tool))))

    (when (= *file* (System/getProperty "babashka.file"))
    (-main *command-line-args*))