Skip to content

Commit

Permalink
Fix zen cli
Browse files Browse the repository at this point in the history
Co-authored-by: @islambegkatibov <79331750+islambegk@users.noreply.github.com>
  • Loading branch information
ApricotLace and katibov committed Jan 24, 2023
1 parent 31f5a0f commit 3bc0f00
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 16 deletions.
2 changes: 1 addition & 1 deletion build/build.clj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

(defn uber [_]
(clean nil)
(b/copy-dir {:src-dirs ["src"]
(b/copy-dir {:src-dirs ["src" "zrc"]
:target-dir class-dir})
(b/compile-clj {:basis basis
:src-dirs ["src"]
Expand Down
2 changes: 1 addition & 1 deletion deps.edn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{:paths ["src" "resources"]
{:paths ["src" "resources" "zrc"]

:deps {org.clojure/clojure {:mvn/version "1.11.1"}
progrock/progrock {:mvn/version "0.1.2"}
Expand Down
7 changes: 7 additions & 0 deletions src/ftr/utils/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -189,3 +189,10 @@

(defn separate-vs&module-names [module+vs-name]
(second (str/split module+vs-name #"\." 2)))


(defn gunzip [input output]
(with-open [rdr (-> input
(java.io.FileInputStream.)
(java.util.zip.GZIPInputStream.))]
(spit output (slurp rdr))))
33 changes: 19 additions & 14 deletions src/ftr/zen_cli.clj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[clojure.pprint]
[zen.core]
[zen.store]
[cli-matic.core]))
[zen.cli-tools]))


(defmethod zen.v2-validation/compile-key :zen.fhir/value-set
Expand All @@ -23,25 +23,30 @@
vtx))})


(def cfg (-> zen.cli/commands
(assoc "build-ftr" (fn [opts]
(let [ztx (zen.cli/load-ztx opts)]
(zen.cli/load-used-namespaces ztx #{})
(ftr.zen-package/build-ftr ztx {:enable-logging? true}))))
(assoc "get-ftr-index-info" ftr.zen-package/get-ftr-index-info)))
(defmethod zen.cli-tools/command 'extended-zen-cli/build-ftr [_ _ opts]
(let [ztx (zen.cli/load-ztx opts)]
(zen.cli/load-used-namespaces ztx #{})
(ftr.zen-package/build-ftr ztx {:enable-logging? true})))


(defmethod zen.cli-tools/command 'extended-zen-cli/get-ftr-index-info [_ _ opts]
(ftr.zen-package/get-ftr-index-info opts))


(defn -main
[& [cmd-name & args]]
(let [og-read-ns zen.core/read-ns]
[& args]
(let [og-read-ns zen.core/read-ns
ztx (zen.core/new-context)
_ (zen.core/read-ns ztx 'extended-zen-cli)]
(with-redefs
[zen.core/read-ns (fn [ztx zen-ns]
(og-read-ns ztx zen-ns)
(ftr.zen-package/build-complete-ftr-index ztx))
(let [read-ns-result (og-read-ns ztx zen-ns)]
(ftr.zen-package/build-complete-ftr-index ztx)
read-ns-result))
zen.core/validate (fn [ztx symbols data]
(-> (ftr.zen-package/validate ztx symbols data)
(select-keys [:errors :warnings :effects])))]
(if (some? cmd-name)
(clojure.pprint/pprint (zen.cli/cmd cfg cmd-name args))
(zen.cli/repl cfg))
(clojure.pprint/pprint (zen.cli-tools/cli-main ztx 'extended-zen-cli/config args {:prompt-fn
#(do (print "ftr> ")
(flush))}))
(System/exit 0))))
26 changes: 26 additions & 0 deletions zrc/extended-zen-cli.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{ns extended-zen-cli
import #{zen.cli-tools
zen.cli} #_"This 2 deps comes transitively from zen-lang/zen and zen-lang/zen <- zen-lang/cli"


build-ftr
{:zen/tags #{zen.cli-tools/command}
:zen/desc "build-ftr"
:args-style :positional
:args {:type zen/vector
:maxItems 0}}


get-ftr-index-info
{:zen/tags #{zen.cli-tools/command}
:zen/desc "get-ftr-index-info"
:args-style :positional
:args {:type zen/vector
:maxItems 0}}


config
{:zen/tags #{zen.cli-tools/config}
:commands {:build-ftr {:command build-ftr}
:get-ftr-index-info {:command get-ftr-index-info}
:zen {:config zen.cli/config}}}}

0 comments on commit 3bc0f00

Please sign in to comment.