Skip to content

Commit

Permalink
Add support for aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
Miikka Koskinen committed Jul 22, 2019
1 parent 4e5e9b8 commit 141d54f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
1 change: 1 addition & 0 deletions deps.edn
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{:deps {nvd-clojure {:mvn/version "1.1.1"}
metosin/jsonista {:mvn/version "0.2.3"}
org.clojure/tools.cli {:mvn/version "0.4.2"}
org.clojure/tools.deps.alpha {:mvn/version "0.7.527" :exclusions [org.slf4j/slf4j-nop]}}}
39 changes: 31 additions & 8 deletions src/clj_nvd/core.clj
Original file line number Diff line number Diff line change
@@ -1,25 +1,37 @@
(ns clj-nvd.core
(:require [clojure.java.io :as io]
[clojure.string :as string]
[clojure.tools.cli :as cli]
[clojure.tools.deps.alpha :as deps]
[clojure.tools.deps.alpha.reader :as deps.reader]
[jsonista.core :as json]
[nvd.task.check]
[nvd.task.purge-database]
[nvd.task.update-database]))

(defn make-classpath []
(let [lib-map (-> (deps.reader/read-deps [(io/file "deps.edn")])
(deps/resolve-deps nil))]
(defn make-classpath [aliases]
(let [deps-map (deps.reader/read-deps (deps.reader/default-deps))
args-map (deps/combine-aliases deps-map aliases)
lib-map (deps/resolve-deps deps-map args-map)]
(mapcat :paths (vals lib-map))))

(defn -main [command & args]
(defn parse-aliases [alias-str]
(map keyword (string/split alias-str #":")))

(def +cli-options+
[["-A" nil "Colon-separated list of deps.edn aliases"
:id :aliases
:required "ALIASES"
:parse-fn parse-aliases]])

(defn run-nvd [aliases command args]
(let [config (try
(read-string (slurp "clj-nvd.edn"))
(catch java.io.FileNotFoundException _
nil))
(read-string (slurp "clj-nvd.edn"))
(catch java.io.FileNotFoundException _
nil))
temp-file (java.io.File/createTempFile "clj-nvd" ".json")
path (.getAbsolutePath temp-file)
classpath (make-classpath)
classpath (make-classpath aliases)
opts {:nvd config
:classpath classpath
:cmd-args args}]
Expand All @@ -31,3 +43,14 @@
(do
(.println *err* (str "No such command: " command))
(System/exit 1)))))

(defn -main [& args]
(let [{:keys [options arguments errors]} (cli/parse-opts args +cli-options+)]
(cond
errors
(do
(.println *err* (string/join \newline errors))
(System/exit 1))

true
(run-nvd (:aliases options) (first arguments) (rest arguments)))))

0 comments on commit 141d54f

Please sign in to comment.