From 10da7ccd3fec272a04b0c9c5ac4784e1d4593e46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Som=C4=93=20Cho?= Date: Sun, 2 Jul 2023 16:46:02 +0200 Subject: [PATCH] 0.0.20 - implement no argument behavior of update command --- build.clj | 2 +- src/depo/core.clj | 8 ++++++-- src/depo/readwrite.clj | 24 ++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/build.clj b/build.clj index 7a942d3..d7c9f66 100644 --- a/build.clj +++ b/build.clj @@ -3,7 +3,7 @@ [deps-deploy.deps-deploy :as dd])) (def lib 'org.clojars.some/depo) -(def version "0.0.19") +(def version "0.0.20") (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 1e1f24c..af72da9 100644 --- a/src/depo/core.clj +++ b/src/depo/core.clj @@ -22,12 +22,16 @@ (defn update-cmd [{:keys [_arguments file]}] (let [args _arguments config-path (if file file (rw/get-config))] - (println args))) + (if (empty? args) + (do (mapv #(rw/update-dependency config-path %) + (rw/get-all-dependency-names config-path)) + (println "Done!")) + (mapv #(rw/update-dependency config-path %) args)))) (def CONFIGURATION {:command "depo" :description "Manage dependencies for Clojure projects easily" - :version "0.0.19" + :version "0.0.20" :opts [{:as "path to configuration file" :default nil :option "file" diff --git a/src/depo/readwrite.clj b/src/depo/readwrite.clj index f242496..5d9ef04 100644 --- a/src/depo/readwrite.clj +++ b/src/depo/readwrite.clj @@ -141,6 +141,30 @@ :wrap-coll? nil}}) (as-> new-conf (spit config-path new-conf))))) +(defmulti get-all-dependency-names + "Returns all the dependencies from the config" + (fn [config-path] config-path)) + +(defmethod get-all-dependency-names :default + [config-path] + (let [zloc (z/of-string (slurp config-path))] + (-> zloc + (z/get :deps) + (z/string) + (read-string) + (keys) + (as-> keys (map str keys))))) + +(defmethod get-all-dependency-names "project.clj" + [config-path] + (let [zloc (z/of-string (slurp config-path))] + (-> zloc + (z/find-value z/next :dependencies) + (z/next) + (z/string) + (read-string) + (as-> dep-vec (map #(str (first %)) dep-vec))))) + (defmulti update-dependency "Updates a dependency in a Clojure project" (fn [config-path dependency] config-path))