Skip to content

Commit 6806924

Browse files
committed
Move to lread.status-line for script status msgs
Moved internal script helper.status out to its own project so that I can reuse it across projects.
1 parent fa98c2f commit 6806924

26 files changed

+151
-275
lines changed

.clj-kondo/config.edn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{:config-paths ^:replace []
1+
{:config-paths ^:replace ["lread/status-line"]
22
:lint-as
33
{ clojure.test.check.clojure-test/defspec clojure.core/def
44
clojure.test.check.properties/for-all clojure.core/let
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{:lint-as {lread.status-line/line clojure.tools.logging/infof
2+
lread.status-line/die clojure.tools.logging/infof}}

bb.edn

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@
44
docopt/docopt {:git/url "https://github.com/nubank/docopt.clj"
55
:sha "98814f559d2e50fdf10f43cbe3b7da0ca3cca423"}
66
doric/doric {:mvn/version "0.9.0"}
7-
version-clj/version-clj {:mvn/version "2.0.1"}}}
7+
version-clj/version-clj {:mvn/version "2.0.1"}
8+
lread/status-line {:git/url "https://github.com/lread/status-line.git"
9+
:sha "35ed39645038e81b42cb15ed6753b8462e60a06d"}}}

script/apply_import_vars.clj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
(ns apply-import-vars
44
(:require [helper.env :as env]
55
[helper.shell :as shell]
6-
[helper.status :as status]))
6+
[lread.status-line :as status]))
77

88
(defn -main[& args]
99
(env/assert-min-versions)
1010
(let [cmd (first args)]
1111
(when (not (#{"gen-code" "check"} cmd))
12-
(status/fatal "Usage: apply-import-vars [gen-code|check]"))
13-
(status/line :info (str "Running apply import vars " cmd))
12+
(status/die 1 "Usage: apply-import-vars [gen-code|check]"))
13+
(status/line :head (str "Running apply import vars " cmd))
1414
(shell/command ["clojure" "-X:apply-import-vars:script" cmd])
1515
nil))
1616

script/ci_tests.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
(:require [helper.env :as env]
55
[helper.fs :as fs]
66
[helper.shell :as shell]
7-
[helper.status :as status]))
7+
[lread.status-line :as status]))
88

99
(defn clean []
1010
(doseq [dir ["target" ".cpcache .shadow-cljs"]]

script/clj_tests.clj

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
[clojure.tools.cli :as cli]
66
[helper.env :as env]
77
[helper.shell :as shell]
8-
[helper.status :as status]))
8+
[lread.status-line :as status]))
99

1010
(def allowed-clojure-versions '("1.9" "1.10"))
1111
(def default-clojure-version "1.10")
@@ -40,17 +40,16 @@
4040
(defn exit [code msg]
4141
(if (zero? code)
4242
(status/line :detail msg)
43-
(status/line :error msg))
44-
(System/exit code))
43+
(status/die code msg)))
4544

4645
(defn run-unit-tests [{:keys [:clojure-version]}]
47-
(status/line :info (str "testing clojure source against clojure v" clojure-version))
46+
(status/line :head (str "testing clojure source against clojure v" clojure-version))
4847
(shell/command ["clojure"
4948
(str "-M:test-common:kaocha:" clojure-version)
5049
"--reporter" "documentation"]))
5150

5251
(defn run-isolated-tests[{:keys [:clojure-version]}]
53-
(status/line :info (str "running isolated tests against clojure v" clojure-version))
52+
(status/line :head (str "running isolated tests against clojure v" clojure-version))
5453
(shell/command ["clojure" (str "-M:kaocha:" clojure-version)
5554
"--profile" "test-isolated"
5655
"--reporter" "documentation"]))

script/clj_watch.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
(ns clj-watch
44
(:require [helper.env :as env]
55
[helper.shell :as shell]
6-
[helper.status :as status]))
6+
[lread.status-line :as status]))
77

88
(defn -main []
99
(env/assert-min-versions)
10-
(status/line :info "launching kaocha watch on clojure sources")
10+
(status/line :head "launching kaocha watch on clojure sources")
1111
(shell/command (concat ["clojure" "-M:test-common:kaocha" "--watch"] *command-line-args*)))
1212

1313
(env/when-invoked-as-script

script/cljdoc_preview.clj

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
[helper.env :as env]
1111
[helper.fs :as fs]
1212
[helper.shell :as shell]
13-
[helper.status :as status]))
13+
[lread.status-line :as status]))
1414

1515
;;
1616
;; constants
@@ -29,7 +29,7 @@
2929
(defn check-prerequisites []
3030
(let [missing-cmds (doall (remove #(fs/on-path %) ["git" "docker"]))]
3131
(when (seq missing-cmds)
32-
(status/fatal (string/join "\n" ["Required commands not found:"
32+
(status/die 1 (string/join "\n" ["Required commands not found:"
3333
(string/join "\n" missing-cmds)])))))
3434
;;
3535
;; os/fs support
@@ -51,9 +51,9 @@
5151
(apply zxml/xml1-> (concat [xml] tag-path [zxml/text]))))
5252

5353
(defn local-install []
54-
(status/line :info "building thin jar")
54+
(status/line :head "building thin jar")
5555
(shell/command ["clojure" "-X:jar"])
56-
(status/line :info "installing project to local maven repo")
56+
(status/line :head "installing project to local maven repo")
5757
(shell/command ["clojure" "-X:deploy:local"]))
5858

5959
(defn get-project []
@@ -107,7 +107,7 @@
107107
{:out :string})]
108108
(if (zero? exit)
109109
(-> out string/trim seq)
110-
(status/fatal "Failed to check for unpushed commits to branch, is your branch pushed?"))))
110+
(status/die 1 "Failed to check for unpushed commits to branch, is your branch pushed?"))))
111111

112112
;;
113113
;; docker
@@ -125,17 +125,20 @@
125125

126126
(defn stop-server [ container ]
127127
(when (= "down" (status-server container))
128-
(status/fatal (str (:name container) " does not appear to be running")))
128+
(status/die 1
129+
"%s does not appear to be running"
130+
(:name container)))
129131
(shell/command ["docker" "stop" (:name container) "--time" "0"]))
130132

131133
(defn wait-for-server
132134
"Wait for container's http server to become available, assumes server has valid root page"
133135
[ container ]
134-
(status/line :info (str "Waiting for " (:name container) " to become available"))
136+
(status/line :head "Waiting for %s to become available" (:name container))
135137
(when (= "down" (status-server container))
136-
(status/fatal (string/join "\n" [(str (:name container) " does not seem to be running.")
137-
"Did you run this script with the start command yet?"])))
138-
(status/line :detail (str (:name container) " container is running"))
138+
(status/die 1
139+
"%s does not seem to be running.\nDid you run this script with the start command yet?"
140+
(:name container)))
141+
(status/line :detail "%s container is running" (:name container))
139142
(let [url (str "http://localhost:" (:port container))]
140143
(loop []
141144
(try
@@ -154,7 +157,7 @@
154157
;;
155158

156159
(defn cljdoc-ingest [container project version]
157-
(status/line :info (str "Ingesting project " project " " version "\ninto local cljdoc database"))
160+
(status/line :head "Ingesting project %s %s\ninto local cljdoc database" project version)
158161
(shell/command ["docker"
159162
"run" "--rm"
160163
"-v" (str cljdoc-db-dir ":/app/data")
@@ -173,10 +176,12 @@
173176

174177
(defn start-cljdoc-server [container]
175178
(when (= "up" (status-server container))
176-
(status/fatal (str (:name container) " is already running")))
177-
(status/line :info "Checking for updates")
179+
(status/die 1
180+
"%s is already running"
181+
(:name container)))
182+
(status/line :head "Checking for updates")
178183
(docker-pull-latest container)
179-
(status/line :info (str "Starting " (:name container) " on port " (:port container)))
184+
(status/line :head "Starting %s on port %d" (:name container) (:port container))
180185
(shell/command ["docker"
181186
"run" "--rm"
182187
"--name" (:name container)
@@ -188,11 +193,9 @@
188193
(:image container)]))
189194

190195
(defn view-in-browser [url]
191-
(status/line :info (str "opening " url " in browser"))
196+
(status/line :head "opening %s in browser" url)
192197
(when (not= 200 (:status (curl/get url {:throw false})))
193-
(status/fatal (string/join "\n" ["Could not reach:"
194-
url
195-
"\nDid you run this script with ingest command yet?"])))
198+
(status/die 1 "Could not reach:\n%s\nDid you run this script with ingest command yet?" url))
196199
(browse/browse-url url))
197200

198201

script/cljs_tests.clj

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
[helper.env :as env]
88
[helper.fs :as fs]
99
[helper.shell :as shell]
10-
[helper.status :as status]))
10+
[lread.status-line :as status]))
1111

1212
(def valid-envs '("node" "chrome-headless" "planck"))
1313
(def valid-optimizations '("none" "advanced"))
@@ -48,9 +48,7 @@
4848
(defn exit [code msg]
4949
(if (zero? code)
5050
(status/line :detail msg)
51-
(status/line :error msg))
52-
(System/exit code))
53-
51+
(status/die code msg)))
5452

5553
(defn compile-opts [out-dir {:keys [:env :optimizations]}]
5654
{:warnings {:fn-deprecated false}
@@ -80,9 +78,7 @@
8078
(string/split #" ")))
8179

8280
(defn run-tests [{:keys [:env :optimizations :run-granularity] :as opts}]
83-
(status/line :info (format "testing ClojureScript source under %s, cljs optimizations: %s"
84-
env
85-
optimizations))
81+
(status/line :head "testing ClojureScript source under %s, cljs optimizations: %s" env optimizations)
8682
(let [test-combo (str env "-" optimizations)
8783
out-dir (str "target/cljsbuild/test/" test-combo)
8884
compile-opts-fname (str out-dir "-cljs-opts.edn")
@@ -105,13 +101,12 @@
105101
"all" (shell/command cmd)
106102
;; I sometimes use namespace granularity to figure out which tests are affecting graal testing
107103
"namespace" (do
108-
(status/line :info "+ one run for each namespace")
104+
(status/line :head "+ one run for each namespace")
109105
(let [nses (find-test-namespaces)
110106
total-nses (count nses)]
111107
(doall (map-indexed
112108
(fn [ndx ns]
113-
(status/line :info (format "%d of %d) running tests for namespace: %s"
114-
(inc ndx) total-nses ns))
109+
(status/line :head "%d of %d) running tests for namespace: %s" (inc ndx) total-nses ns)
115110
(shell/command (concat cmd ["--namespace" ns])))
116111
nses)))))))
117112

script/cljs_watch.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
(ns cljs-watch
44
(:require [helper.env :as env]
55
[helper.shell :as shell]
6-
[helper.status :as status]))
6+
[lread.status-line :as status]))
77

88
(defn -main []
99
(env/assert-min-versions)

0 commit comments

Comments
 (0)