|
4 | 4 | [camel-snake-kebab.core :as csk] |
5 | 5 | [gitwerk.command.clone :as command.clone] |
6 | 6 | [gitwerk.command.log :as command.log] |
| 7 | + [gitwerk.command.sci :as command.sci] |
7 | 8 | [gitwerk.command.semver :as command.semver] |
8 | 9 | [gitwerk.command.semver-auto :as command.semver-auto] |
9 | 10 | [gitwerk.command.tag :as command.tag])) |
10 | 11 |
|
| 12 | +(def primitives |
| 13 | + {:clone |
| 14 | + {:command command.clone/run |
| 15 | + :description "clone git repository"} |
| 16 | + :log |
| 17 | + {:command command.log/run |
| 18 | + :description "show git logs of current directory"} |
| 19 | + :semver |
| 20 | + {:command command.semver/run |
| 21 | + :description "print incremented version"} |
| 22 | + :semver-auto |
| 23 | + {:command command.semver-auto/run |
| 24 | + :description "increment version by latest git log message contexts"} |
| 25 | + :tag |
| 26 | + {:command command.tag/run |
| 27 | + :description "show git tags of current directory"}}) |
| 28 | + |
| 29 | +(def definitions |
| 30 | + (let [->binding (fn [[k v]] |
| 31 | + (let [sym (symbol (name k)) |
| 32 | + com (:command v)] |
| 33 | + [sym com])) |
| 34 | + bindings (->> primitives |
| 35 | + (map ->binding) |
| 36 | + (into {})) |
| 37 | + sci-opts {:bindings bindings}] |
| 38 | + (into primitives |
| 39 | + {:sci {:command (command.sci/run-fn sci-opts) |
| 40 | + :description "run user-defined script (written in clojure)"}}))) |
| 41 | + |
11 | 42 | (defn dispatch |
12 | 43 | [{:keys [args] :as ctx} cmd] |
13 | 44 | (let [default (fn [_ _] |
14 | 45 | {:status 1 |
15 | 46 | :invalid-arg? true}) |
16 | | - cmd (case cmd |
17 | | - :clone command.clone/run |
18 | | - :log command.log/run |
19 | | - :semver command.semver/run |
20 | | - :semver-auto command.semver-auto/run |
21 | | - :tag command.tag/run |
22 | | - default)] |
| 47 | + cmd (or (:command (cmd definitions)) default)] |
23 | 48 | (cmd ctx args))) |
24 | 49 |
|
25 | 50 | (defn run |
|
0 commit comments