diff --git a/build.clj b/build.clj index 13bb18e..02fd778 100644 --- a/build.clj +++ b/build.clj @@ -4,7 +4,7 @@ [deps-deploy.deps-deploy :as dd])) (def lib 'org.clojars.some/depo) -(def version "0.0.13") +(def version "0.0.14") (def jar-file (format "target/%s-%s.jar" (name lib) version)) (def class-dir "target/classes") (def url "https://github.com/somecho/depo") diff --git a/src/depo/core.clj b/src/depo/core.clj index b677444..9b98dfe 100644 --- a/src/depo/core.clj +++ b/src/depo/core.clj @@ -22,7 +22,8 @@ (let [args _arguments config-path (if file file (rw/get-config))] (if-not (empty? args) - (println "TODO") + (do (mapv #(rw/remove-dependency config-path %) args) + (println "Done!")) (println (e/err :no-args))))) (def remove-cmd {:command "remove" @@ -32,13 +33,14 @@ (def CONFIGURATION {:command "depo" :description "Manage dependencies for Clojure projects easily" - :version "0.0.13" + :version "0.0.14" :opts [{:as "path to configuration file" :default nil :option "file" :short "f" :type :string}] - :subcommands [add-cmd]}) + :subcommands [add-cmd + remove-cmd]}) (defn -main [& args] diff --git a/src/depo/readwrite.clj b/src/depo/readwrite.clj index d35b085..334eb70 100644 --- a/src/depo/readwrite.clj +++ b/src/depo/readwrite.clj @@ -1,5 +1,6 @@ (ns depo.readwrite (:require [clojure.java.io :as io] + [depo.parser :as dp] [depo.resolver :as r] [zprint.core :as zp] [rewrite-clj.zip :as z])) @@ -77,3 +78,32 @@ :vector {:respect-nl? true :wrap-coll? nil}}) (as-> new-conf (spit config-path new-conf))))) + +(defmulti remove-dependency + "Removes the dependency from the given configuration file" + (fn [config-path dependency] config-path)) + +(defmethod remove-dependency :default + [config-path arg] + (let [zloc (z/of-string (slurp config-path)) + {:keys [groupID artifactID]} (dp/parse arg) + identifier (symbol (str groupID "/" artifactID))] + (-> zloc + (z/get :deps) + (z/string) + (read-string) + (as-> dep-map + (if-not (contains? dep-map identifier) + (println arg "isn't a dependency. Skipping.") + (do + (println "Removing" (str identifier)) + (-> dep-map + (dissoc identifier) + (as-> new-deps + (-> zloc + (z/assoc :deps new-deps))) + (z/root-string) + (zp/zprint-str {:parse-string? true + :map {:sort? false + :hang? false}}) + (as-> new-conf (spit config-path new-conf)))))))))