-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathls_jar.clj
executable file
·41 lines (37 loc) · 1.58 KB
/
ls_jar.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env bb
(ns ls-jar
(:require
[babashka.cli :as cli]
[clojure.java.io :as io]
[clojure.string :as str]))
(def spec [[:lib {:desc "Library as fully qualified symbol. Must be accompanied with --version."}]
[:version {:desc "Version"}]
[:jar {:desc "Jar file"}]])
(defn print-help []
(println "Enumerate files from jar files")
(println "Usage: ls_jar <options>")
(println)
(println "Options:")
(println (cli/format-opts {:spec spec}))
(println)
(println "Examples:")
(println "ls_jar --lib babashka/fs --version 0.1.6")
(println "ls_jar --jar ~/.m2/repository/babashka/fs/0.1.6/fs-0.1.6.jar"))
(if (empty? *command-line-args*)
(print-help)
(let [{:keys [jar lib version help]} (cli/parse-opts *command-line-args* {:spec spec})]
(if help (print-help)
(let [file (if jar
(io/file jar)
(if (and lib version)
(let [[_org lib-name] (str/split lib #"/")]
(io/file (System/getProperty "user.home")
(format ".m2/repository/%s/%s/%s-%s.jar"
(str/replace lib "." (System/getProperty "file.separator"))
version
lib-name version)))
(do (println "Provide either --file or: --lib and --version")
(System/exit 1))))]
(doseq [e (enumeration-seq
(.entries (java.util.jar.JarFile. file)))]
(println (.getName e)))))))