|
4 | 4 | [clojure.tools.cli :as cli] |
5 | 5 | [clojure.edn :as edn] |
6 | 6 | [clojure.java.io :as io] |
7 | | - [camel-snake-kebab.core :as csk] |
8 | | - [gitwerk.command.clone :as command.clone] |
9 | | - [gitwerk.command.log :as command.log] |
10 | | - [gitwerk.command.semver :as command.semver] |
11 | | - [gitwerk.command.semver-auto :as command.semver-auto] |
12 | | - [gitwerk.command.tag :as command.tag]) |
| 7 | + [gitwerk.service.runner :as runner]) |
13 | 8 | (:gen-class)) |
14 | 9 |
|
15 | 10 | (def cli-header "Usage: gitwerk [command] [options]") |
16 | 11 | (def cli-options |
17 | 12 | [["-f" "--file PATH" "config" |
18 | 13 | :id :config-filename |
19 | 14 | :default "config.edn"] |
| 15 | + ["-e" "--edn" :id :edn?] |
20 | 16 | ["-d" "--debug" :id :debug?] |
21 | 17 | ["-h" "--help" :id :help?]]) |
22 | 18 |
|
23 | | -(defn run |
24 | | - [{:keys [command args options summary] :as ctx}] |
25 | | - (case (csk/->kebab-case-keyword command) |
26 | | - :clone (command.clone/run ctx args) |
27 | | - :log (command.log/run ctx args) |
28 | | - :semver (command.semver/run ctx args) |
29 | | - :semver-auto (command.semver-auto/run ctx args) |
30 | | - :tag (command.tag/run ctx args) |
31 | | - (do |
| 19 | +(defn edn-output |
| 20 | + [ctx res] |
| 21 | + (println res)) |
| 22 | + |
| 23 | +(defn std-output |
| 24 | + [{:keys [summary] :as ctx} |
| 25 | + {:keys [status invalid-arg? console-out]}] |
| 26 | + (when console-out |
| 27 | + (println console-out)) |
| 28 | + (when invalid-arg? |
32 | 29 | (println cli-header) |
33 | | - (println summary)))) |
| 30 | + (println summary)) |
| 31 | + (if status |
| 32 | + (System/exit status) |
| 33 | + (System/exit 1))) |
| 34 | + |
| 35 | +(defn run |
| 36 | + [{:keys [options] :as ctx}] |
| 37 | + (let [{:keys [edn?]} options |
| 38 | + res (runner/run ctx)] |
| 39 | + (if edn? |
| 40 | + (edn-output ctx res) |
| 41 | + (std-output ctx res)))) |
34 | 42 |
|
35 | 43 | (defn main |
36 | 44 | [{:keys [options summary arguments] :as parsed-result}] |
|
51 | 59 | (cli/parse-opts cli-options) |
52 | 60 | (main)) |
53 | 61 | (catch Exception e |
54 | | - (println (.getMessage e))) |
| 62 | + (println (.getMessage e)) |
| 63 | + (System/exit 1)) |
55 | 64 | (finally |
56 | 65 | (shutdown-agents)))) |
0 commit comments