Skip to content
This repository has been archived by the owner on Oct 1, 2020. It is now read-only.

Commit

Permalink
make csv optional
Browse files Browse the repository at this point in the history
  • Loading branch information
orb committed Apr 20, 2013
1 parent 23a617a commit ff8917d
Showing 1 changed file with 35 additions and 12 deletions.
47 changes: 35 additions & 12 deletions src/leiningen/licenses.clj
@@ -1,5 +1,6 @@
(ns leiningen.licenses
(:require [leiningen.core.classpath :as classpath]
[leiningen.core.main :as main]
[cemerick.pomegranate.aether :as aether]
[clojure.java.io :as io]
[clojure.pprint :as pp]
Expand Down Expand Up @@ -79,17 +80,39 @@
first :content first)
(try-raw-license file)))

(defn quote [text]
(str \" (clojure.string/replace text #"\"" "\"\"") \"))

(def formatters
{":text"
(fn [line]
(string/join " - " line))

":csv"
(fn [line]
(let [quote-csv
(fn [text]
(str \" (clojure.string/replace text #"\"" "\"\"") \"))]
(string/join "," (map quote-csv line))))})


(defn licenses
"List the license of each of your dependencies."
[project]
(let [deps (#'classpath/get-dependencies :dependencies project)
deps (zipmap (keys deps) (aether/dependency-files deps))]
(doseq [[[dep version] file] deps]
(let [line [(pr-str dep)
version
(or (get-licenses dep file) "Unknown")]]

(println (string/join "," (map quote line)))))))
"List the license of each of your dependencies.
USAGE: lein licenses [:text]
Show license information in the default text format
USAGE lein licenses :csv
Show licenses in CSV format"

([project]
(licenses project ":text"))

([project output-style]
(if-let [format-fn (formatters output-style)]
(let [deps (#'classpath/get-dependencies :dependencies project)
deps (zipmap (keys deps) (aether/dependency-files deps))]
(doseq [[[dep version] file] deps]
(let [line [(pr-str dep)
version
(or (get-licenses dep file) "Unknown")]]
(println (format-fn line)))))
(main/abort "unknown formatter"))))

0 comments on commit ff8917d

Please sign in to comment.