-
Notifications
You must be signed in to change notification settings - Fork 12
/
spit.clj
86 lines (67 loc) · 2.94 KB
/
spit.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
(ns metav.cli.spit
(:require
[clojure.spec.alpha :as s]
[clojure.string :as string]
[clojure.data.json :as json]
[metav.cli.common :as cli-common]
[metav.api :as api]))
;;----------------------------------------------------------------------------------------------------------------------
;; Spit conf
;;----------------------------------------------------------------------------------------------------------------------
(defn parse-formats [s]
(into #{}
(comp
(map string/trim)
(map keyword))
(string/split s #",")))
(def cli-options
(conj cli-common/cli-options
["-o" "--output-dir DIR_PATH" "Output Directory"
:id :metav.spit/output-dir
:parse-fn str]
["-n" "--namespace NS" "Namespace used in code output"
:id :metav.spit/namespace]
["-f" "--formats FORMATS" "Comma-separated list of output formats (clj, cljc, cljs, edn, json)"
:id :metav.spit/formats
:parse-fn parse-formats
:validate [(partial s/valid? :metav.spit/formats)
"Formats must be in the following list: clj, cljc, cljs, edn, json"]]
["-t" "--template TEMPLATE" "Template used for rendering (must follows mustache format, spitted data is available during template rendering)"
:id :metav.spit/template
:parse-fn str
:validate [(partial s/valid? :metav.spit/template)
"Template must be a valid path to a java resource."]]
["-d" "--rendering-output RENDERING-OUTPUT" "File to render template in"
:id :metav.spit/rendering-output
:parse-fn str
:validate [(partial s/valid? :metav.spit/rendering-output)
"Rendering output must be a path to an existing directory in the project."]]))
;;----------------------------------------------------------------------------------------------------------------------
;; Assembling spit main
;;----------------------------------------------------------------------------------------------------------------------
(defn usage [summary]
(->> ["The spit function of Metav output module's metadata in files according the given formats among: clj, cljc, cljs, edn or json."
"The metadata is composed of: module-name, tag, version, path, timestamp "
""
"Usage: metav.spit [options]"
""
"Options:"
summary
""]
(string/join \newline)))
(def validate-args
(cli-common/make-validate-args cli-options
usage))
(defn perform! [context]
(when (:metav.cli/verbose? context)
(-> context api/metadata-as-edn json/write-str print))
(api/spit! context))
(def main* (cli-common/make-main
validate-args
perform!))
(comment
(main* "-c" "resources-test/example-conf.edn"
"-f" "cljc, json, edn"
"-n" "metav.meta"
"-t" "mustache-template.txt"))
(def main (cli-common/wrap-exit main*))