self-updater: Add missing when function
[babashka-scripts.git] / lib.clj
CommitLineData
1770a260 1; Common utility functions used by scripts
f1d839f5
JN
2
3(import '[java.nio.file Files FileSystems CopyOption StandardCopyOption])
4
5(defn extract-file-from-zip
6 [zip-file-name source destination]
7 (let [zip-file (io/file zip-file-name)
8 src (io/file source)
9 dest (io/file destination)
10 fs (FileSystems/newFileSystem (.toPath zip-file) nil)
11 file-in-zip (.getPath fs source (into-array String []))]
12 (Files/copy file-in-zip (.toPath dest)
13 (into-array CopyOption [StandardCopyOption/REPLACE_EXISTING]))))
14
15(defn expand-home [s]
16 (if (.startsWith s "~")
17 (clojure.string/replace-first s "~" (System/getProperty "user.home"))
18 s))