Skip to content

Commit

Permalink
implement remove dependency default multimethod and wire it to CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
somecho committed Jul 2, 2023
1 parent 3a9d6e1 commit 9f09e5c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
8 changes: 5 additions & 3 deletions src/depo/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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]
Expand Down
30 changes: 30 additions & 0 deletions src/depo/readwrite.clj
Original file line number Diff line number Diff line change
@@ -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]))
Expand Down Expand Up @@ -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)))))))))

0 comments on commit 9f09e5c

Please sign in to comment.