Skip to content

Commit

Permalink
Refactor some namespaces and format code
Browse files Browse the repository at this point in the history
  • Loading branch information
just-sultanov committed Jan 19, 2024
1 parent 3c5a687 commit 2a93cf7
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 38 deletions.
20 changes: 20 additions & 0 deletions src/main/clojure/xdeps/build.clj
Original file line number Diff line number Diff line change
@@ -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))
8 changes: 2 additions & 6 deletions src/main/clojure/xdeps/cli.clj
Original file line number Diff line number Diff line change
@@ -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}}
Expand All @@ -15,11 +13,9 @@
(help/print-version)
(help/print-help)))})


(def cmds
[default])


(defn dispatch
[args]
(cli/dispatch cmds args {}))
21 changes: 7 additions & 14 deletions src/main/clojure/xdeps/cli/help.clj
Original file line number Diff line number Diff line change
@@ -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 <command> <options>"))


(defn print-options
[]
(println "Options:
--version Show version
--help Show help"))


(defn print-commands
[]
(println "Commands:")
(println "TBD"))


(defn print-help
[]
(print-meta)
Expand Down
35 changes: 23 additions & 12 deletions src/main/clojure/xdeps/config.clj
Original file line number Diff line number Diff line change
@@ -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)))
10 changes: 4 additions & 6 deletions src/main/clojure/xdeps/main.clj
Original file line number Diff line number Diff line change
@@ -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]
Expand Down

0 comments on commit 2a93cf7

Please sign in to comment.