diff --git a/src/main/clojure/xdeps/build.clj b/src/main/clojure/xdeps/build.clj new file mode 100644 index 0000000..192b544 --- /dev/null +++ b/src/main/clojure/xdeps/build.clj @@ -0,0 +1,20 @@ +(ns xdeps.build + (:refer-clojure :exclude [meta]) + (:require + [clojure.edn :as edn] + [clojure.java.io :as io])) + +(set! *warn-on-reflection* true) + +;; Build metadata + +(defn read-meta + [] + (or (some-> "io/lazy-cat/xdeps/meta.edn" + (io/resource) + (slurp) + (edn/read-string)) + {})) + +(def meta + (read-meta)) diff --git a/src/main/clojure/xdeps/cli.clj b/src/main/clojure/xdeps/cli.clj index b601147..afe6244 100644 --- a/src/main/clojure/xdeps/cli.clj +++ b/src/main/clojure/xdeps/cli.clj @@ -1,12 +1,10 @@ (ns xdeps.cli (:require - [babashka.cli :as cli] - [xdeps.cli.help :as help])) - + [babashka.cli :as cli] + [xdeps.cli.help :as help])) (set! *warn-on-reflection* true) - (def default {:cmds [] :spec {:version {:coerce :boolean}} @@ -15,11 +13,9 @@ (help/print-version) (help/print-help)))}) - (def cmds [default]) - (defn dispatch [args] (cli/dispatch cmds args {})) diff --git a/src/main/clojure/xdeps/cli/help.clj b/src/main/clojure/xdeps/cli/help.clj index 2ffc288..b209c55 100644 --- a/src/main/clojure/xdeps/cli/help.clj +++ b/src/main/clojure/xdeps/cli/help.clj @@ -1,45 +1,38 @@ (ns xdeps.cli.help (:require - [clojure.string :as str] - [xdeps.config :as config])) - + [clojure.string :as str] + [xdeps.build :as build])) (set! *warn-on-reflection* true) - (defn print-version [] - (println (:version config/meta))) - + (println (:version build/meta))) (defn print-meta [] - (let [{:keys [version branch commit timestamp]} config/meta - build (->> [branch commit timestamp] - (remove empty?) - (str/join ", "))] + (let [{:keys [version branch commit timestamp]} build/meta + build (->> [branch commit timestamp] + (remove empty?) + (str/join ", "))] (println (format "xdeps %s (%s)" version build)))) - (defn print-usage [] (println "Usage: xdeps ")) - (defn print-options [] (println "Options: --version Show version --help Show help")) - (defn print-commands [] (println "Commands:") (println "TBD")) - (defn print-help [] (print-meta) diff --git a/src/main/clojure/xdeps/config.clj b/src/main/clojure/xdeps/config.clj index 05546f3..ef81027 100644 --- a/src/main/clojure/xdeps/config.clj +++ b/src/main/clojure/xdeps/config.clj @@ -1,20 +1,31 @@ (ns xdeps.config - (:refer-clojure :exclude [meta]) (:require - [clojure.edn :as edn] - [clojure.java.io :as io])) - + [babashka.fs :as fs] + [clojure.edn :as edn])) (set! *warn-on-reflection* true) +;; Default xdeps configuration + +(def defaults + {}) + +(defn read-config + [root] + (let [path (fs/path root "config.edn")] + (if (fs/exists? path) + (some-> path (str) (slurp) (edn/read-string)) + (do + ;; provide the default config + (fs/create-dir root) + (spit (str path) defaults) + defaults)))) -(defn read-meta - [] - (some-> "io/lazy-cat/xdeps/meta.edn" - (io/resource) - (slurp) - (edn/read-string))) +;; Global xdeps configuration +#_:clj-kondo/ignore -(def meta - (read-meta)) +(def global + (-> "xdeps" + (fs/xdg-config-home) + (read-config))) diff --git a/src/main/clojure/xdeps/main.clj b/src/main/clojure/xdeps/main.clj index 98adfee..2d41a3a 100644 --- a/src/main/clojure/xdeps/main.clj +++ b/src/main/clojure/xdeps/main.clj @@ -1,12 +1,10 @@ - (ns xdeps.main - (:gen-class) - (:require - [xdeps.cli :as cli])) - +(ns xdeps.main + (:gen-class) + (:require + [xdeps.cli :as cli])) (set! *warn-on-reflection* true) - (defn -main "Application entrypoint." [& args]