-
Notifications
You must be signed in to change notification settings - Fork 28
/
specs.cljc
126 lines (84 loc) · 3.41 KB
/
specs.cljc
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
(ns cli-matic.specs
(:require [clojure.spec.alpha :as s]))
(defn has-elements? [s]
(pos? (count s)))
(s/def ::anything (s/or :nil nil?
:some some?))
(s/def ::existing-string (s/and string? has-elements?))
(s/def ::climatic-errors #{:ERR-CFG
:ERR-NO-SUBCMD
:ERR-UNKNOWN-SUBCMD
:ERR-PARMS-GLOBAL
:ERR-PARMS-SUBCMD})
;; The way your process runs; will generate
;; a return val and some lines for stdout/stderr.
(s/def ::retval int?)
(s/def ::status (s/or :oth #{:OK :EXCEPTION}
:err ::climatic-errors))
(s/def ::help (s/or :none nil?
:some #{:HELP-GLOBAL :HELP-SUBCMD}))
(s/def ::subcmd (s/or :none ::existing-string
:nil nil?))
(s/def ::stderr (s/coll-of string?))
(s/def ::RV
(s/keys :req-un [::retval ::status ::help ::subcmd ::stderr]))
;; Cli-matic option definition
(s/def ::option ::existing-string) ;; ex-string
(s/def ::positional-arg (s/and integer?
(s/or :z zero? :p pos?)))
(s/def ::short (s/or :str ::existing-string
:pos ::positional-arg))
(s/def ::as ::existing-string)
(s/def ::set-of-strings
(s/and set?
(s/coll-of ::existing-string :min-count 1)))
(s/def ::set-of-kws
(s/and set?
(s/coll-of keyword? :min-count 1)))
(s/def ::set-of-vals
(s/or :set-str ::set-of-strings
:set-kw ::set-of-kws))
(s/def ::type
(s/or :plain-kw #{:int :int-0
:string :keyword
:float :float-0
:yyyy-mm-dd
:slurp :slurplines
:edn :ednfile
:json :jsonfile
:with-flag :flag
:yaml :yamlfile}
:set-vals ::set-of-vals))
(s/def ::default some?)
(s/def ::env ::existing-string)
(s/def ::spec some?) ; \TODO how do we know it's a valid spec?
(s/def ::climatic-option
(s/keys :req-un [::option ::as ::type]
:opt-un [::short ::default ::env ::spec]))
;; CLI-matic configuration
(s/def ::description (s/or :a-string ::existing-string
:coll-str (s/coll-of string?)))
(s/def ::version ::existing-string)
(s/def ::command ::existing-string)
(s/def ::opts (s/coll-of ::climatic-option))
(s/def ::runs ifn?)
(s/def ::on-shutdown ifn?)
(s/def ::app (s/keys :req-un [::command ::description ::version]))
(s/def ::global-opts ::opts)
(s/def ::a-command (s/keys :req-un [::command ::opts ::runs]
:opt-un [::short ::description ::spec ::on-shutdown]))
(s/def ::commands (s/coll-of ::a-command))
(s/def ::climatic-cfg (s/keys :req-un [::app ::global-opts ::commands]))
;; Parsing of options.
(s/def ::subcommand (s/or :empty nil?
:some ::existing-string))
(s/def ::subcommand-def (s/or :empty nil?
:some ::a-command))
(s/def ::commandline map?) ;; contains :_arguments as vec
(s/def ::parse-errors (s/or :oth #{:NONE :HELP-GLOBAL :HELP-SUBCMD}
:err ::climatic-errors))
(s/def ::error-text string?)
(s/def ::lineParseResult (s/keys :req-un [::subcommand ::subcommand-def ::commandline ::parse-errors ::error-text]))
;; Return value of parsing with tools.cli
(s/def ::parsedCliOpts map?)
(s/def ::mapOfCliParams (s/map-of string? (s/or :empty nil? :str string?)))