Skip to content

Instantly share code, notes, and snippets.

@tylerw
Created June 18, 2022 19:23
Show Gist options
  • Save tylerw/83be543f2fb983033919fe0423a80ae8 to your computer and use it in GitHub Desktop.
Save tylerw/83be543f2fb983033919fe0423a80ae8 to your computer and use it in GitHub Desktop.
Quick-and-dirty script to update all Clojure -Ttools
#!/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*))
@tylerw
Copy link
Author

tylerw commented Jul 6, 2022

As of Clojure CLI 1.11.1.1149 this functionality is builtin: clj -Ttools install-latest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment