diff --git a/project.clj b/project.clj index a404441..439e6a4 100644 --- a/project.clj +++ b/project.clj @@ -1,5 +1,5 @@ -(defproject depo "0.0.5" +(defproject depo "0.0.6" :description "Manage Clojure dependencies easily" :url "https://github.com/somecho/depo" - :license {:name "Eclipse Public License, v2" - :url "http://www.eclipse.org/legal/epl-v20.html"}) + :license {:name "Eclipse Public License, v2", + :url "http://www.eclipse.org/legal/epl-v20.html"}) diff --git a/src/depo/core.clj b/src/depo/core.clj index 9d7bfd8..c254e91 100644 --- a/src/depo/core.clj +++ b/src/depo/core.clj @@ -4,7 +4,6 @@ [depo.errors :as e])) (defn add [{:keys [_arguments file]}] - (println file) (let [args _arguments config-path (if file file (rw/get-config))] (if-not (empty? args) @@ -18,7 +17,7 @@ (def CONFIGURATION {:command "depo" :description "manage Clojure dependencies easily" - :version "0.0.5" + :version "0.0.6" :opts [{:as "path to configuration file" :default nil :option "file" diff --git a/src/depo/readwrite.clj b/src/depo/readwrite.clj index 2b671ab..4461eaa 100644 --- a/src/depo/readwrite.clj +++ b/src/depo/readwrite.clj @@ -38,3 +38,40 @@ (zp/zprint-str {:parse-string? true :map {:sort? false}}) (as-> new-conf (spit config-path new-conf))))) + +(defmethod write-dependency "project.clj" + [config-path arg] + (let [zloc (z/of-string (slurp config-path)) + {:keys [groupID artifactID version]} (r/conform-version arg) + dep-sym (symbol (if (= groupID artifactID) + artifactID + (str groupID "/" artifactID))) + zipper (if (z/find-value zloc z/next :dependencies) + zloc + (-> zloc + (z/append-child :dependencies) + (z/append-child [])))] + (println (str "Adding " groupID "/" artifactID " v" version)) + (-> zipper + (z/find-value z/next :dependencies) + (z/right) + (z/string) + (read-string) + (as-> dep-vec + (filter #(not= dep-sym (first %)) dep-vec)) + (vec) + (conj [dep-sym version]) + (as-> new-deps + (-> zipper + (z/find-value z/next :dependencies) + (z/right) + (z/replace new-deps))) + (as-> veczip + (z/map (fn [z] (if (z/rightmost? z) + z + (z/insert-newline-right z))) veczip)) + (z/root-string) + (zp/zprint-str {:parse-string? true + :vector {:respect-nl? true + :wrap-coll? nil}}) + (as-> new-conf (spit config-path new-conf)))))