Skip to content

Commit c780668

Browse files
committed
feat: Honor BARK_CONFIG env var across daemon and bb scripts
1 parent a94a88d commit c780668

10 files changed

Lines changed: 59 additions & 24 deletions

File tree

README.org

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,21 @@ bb export html --theme none # no theme
164164

165165
* Configuration
166166

167-
See =config.edn.example=. The configuration has three main sections:
167+
See =config.edn.example=. The configuration has three main sections.
168+
169+
** Config file location
170+
171+
By default BARK reads =./config.edn= (from the current working
172+
directory). To override:
173+
174+
- Pass =-c <path>= to the JVM daemon: =clj -M:run -- -c /path/to/config.edn=
175+
- Or set the =BARK_CONFIG= env var — all =bb= scripts (=bb export=,
176+
=bb notify=, =bb maintenance=, =bb test-config=, …) honor it.
177+
178+
Precedence: CLI =-c= flag > =BARK_CONFIG= env var > =./config.edn=.
179+
180+
The script-level =BARK_DB= env var (legacy) still works as a fallback
181+
when the config has no =:db {:path …}= entry.
168182

169183
** Mail source (=:mailbox=)
170184

config.edn.example

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
;; BARK config — reference template.
2+
;;
3+
;; By default BARK reads ./config.edn. Override via:
4+
;; - CLI: clj -M:run -- -c /path/to/config.edn
5+
;; - env: BARK_CONFIG=/path/to/config.edn (also honored by all bb scripts)
6+
;; Precedence: -c > BARK_CONFIG > ./config.edn.
7+
18
{ ;; ---- Connection --------------------------------------------------------
29

310
;; Mail source — IMAP or Maildir. :folder defaults to "INBOX".

scripts/bark-docs.clj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
'[bark.common :refer [default-labels default-commands
2020
resolve-labels-map resolve-commands-map
2121
resolve-command-syntax
22-
parse-cli-args load-config build-source-map
22+
parse-cli-args load-config db-path build-source-map
2323
format-date-iso bark-schema lead-maintainer]]
2424
'[bark.common-bb :refer [load-datalevin-pod! get-tenures]]
2525
'[bark.html-bb :refer [pico-cdn resolved-theme set-theme!
@@ -450,9 +450,9 @@
450450
effective-dir (or out-dir
451451
(.getParent (io/file out-file)))
452452
;; Load DB for maintainer names
453-
db-path (or (System/getenv "BARK_DB") "data/bark-db")
453+
dbp (db-path config)
454454
_ (load-datalevin-pod!)
455-
conn ((resolve 'pod.huahaiy.datalevin/get-conn) db-path bark-schema {:wal? false})
455+
conn ((resolve 'pod.huahaiy.datalevin/get-conn) dbp bark-schema {:wal? false})
456456
db ((resolve 'pod.huahaiy.datalevin/db) conn)
457457
maint-html (build-maintainers-html db source-name)
458458
config-html (build-configuration-html config source-name)

scripts/bark-export.clj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
format-date format-date-iso
5454
report-priority report-status report-descendant-count
5555
parse-cli-args parse-delay parse-cutoff-date
56-
load-config build-source-map
56+
load-config db-path build-source-map
5757
bark-schema bark-format
5858
votes-by-report vote-counts
5959
ics-file? text-attachment?]]
@@ -1256,8 +1256,9 @@
12561256
topics-filter]
12571257
:or {format "all"}}
12581258
(parse-cli-args *command-line-args*)
1259-
db-path (or (System/getenv "BARK_DB") "data/bark-db")
1260-
conn (d/get-conn db-path bark-schema {:wal? false})]
1259+
config (load-config)
1260+
dbp (db-path config)
1261+
conn (d/get-conn dbp bark-schema {:wal? false})]
12611262
(try
12621263
(when-not (formats format)
12631264
(log/error "Unknown format:" format)
@@ -1280,10 +1281,9 @@
12801281
(.getTime ^java.util.Date last-export)))]
12811282
(if skip?
12821283
(log/info "Nothing changed since last export, skipping.")
1283-
;; Resolve config and source list *before* the expensive DB pull
1284+
;; Resolve source list *before* the expensive DB pull
12841285
;; so we can determine which sources actually need re-export.
1285-
(let [config (load-config)
1286-
effective-theme (or theme (:theme config))
1286+
(let [effective-theme (or theme (:theme config))
12871287
_ (when effective-theme (set-theme! effective-theme))
12881288
source-map (if config (build-source-map config) {})
12891289
source-names (if source-name

scripts/bark-maintenance.clj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
(require '[clojure.string :as str]
2424
'[taoensso.timbre :as log]
2525
'[bark.common :refer [parse-delay parse-cutoff-date
26-
load-config build-source-map
26+
load-config db-path build-source-map
2727
bark-schema format-date
2828
failures-file-path read-failures-file
2929
reason-labels]]
@@ -148,18 +148,18 @@
148148

149149
(let [{:keys [delete? verbose? failures? source-name] :as opts}
150150
(parse-args *command-line-args*)
151-
db-path (or (System/getenv "BARK_DB") "data/bark-db")
152151
config (load-config)
153152
_ (when-not config
154153
(log/error "No config.edn found")
155154
(System/exit 1))
155+
dbp (db-path config)
156156
source-map (build-source-map config)
157157
_ (when (and source-name (not (contains? source-map source-name)))
158158
(log/error "Unknown source:" source-name)
159159
(log/error "Available:" (str/join ", " (keys source-map)))
160160
(System/exit 1))
161161
;; Open with WAL for potential writes
162-
conn (d/get-conn db-path bark-schema {})]
162+
conn (d/get-conn dbp bark-schema {})]
163163
(try
164164
(let [db (d/db conn)]
165165
(if failures?

scripts/bark-notify.clj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
'[taoensso.timbre :as log]
2323
'[bark.common :refer [get-header format-date format-date-iso
2424
report-priority report-status report-descendant-count
25-
load-config build-source-map
25+
load-config db-path build-source-map
2626
bark-schema maintainer?
2727
failures-file-path read-failures-file
2828
reason-labels]]
@@ -330,16 +330,16 @@
330330
force? (flags "--force")
331331
debug? (flags "--debug")
332332
_ (when debug? (log/merge-config! {:min-level :debug}))
333-
db-path (or (System/getenv "BARK_DB") "data/bark-db")
334333
config (load-config)
334+
dbp (db-path config)
335335
notif (:notifications config)]
336336
(when-not (and notif (:enabled notif))
337337
(log/info "Notifications disabled in config.")
338338
(System/exit 0))
339339
(let [smtp (or (:smtp notif)
340340
(do (log/error "No :smtp config under :notifications.")
341341
(System/exit 1)))
342-
conn (d/get-conn db-path bark-schema {:wal? false})]
342+
conn (d/get-conn dbp bark-schema {:wal? false})]
343343
(try
344344
(let [db (d/db conn)
345345
now (java.util.Date.)

scripts/bark-stats.clj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
'[taoensso.timbre :as log]
1919
'[bark.common :refer [report-priority report-status
2020
report-descendant-count format-date format-date-iso
21-
parse-cli-args load-config bark-schema
21+
parse-cli-args load-config db-path bark-schema
2222
votes-by-report vote-counts]]
2323
'[bark.common-bb :refer [load-datalevin-pod! all-reports dq]]
2424
'[bark.html-bb :refer [pico-cdn resolved-theme set-theme!
@@ -35,8 +35,8 @@
3535

3636
(def ^:private stats-js (slurp "resources/bark-stats.js"))
3737

38-
(def db-path
39-
(or (System/getenv "BARK_DB") "./data/bark-db"))
38+
;; db-path is resolved lazily inside generate-json! / generate-html!
39+
;; so loading this namespace doesn't force a config read.
4040

4141
;; ---------------------------------------------------------------------------
4242
;; Time helpers
@@ -603,7 +603,7 @@
603603
(update :closed-cancel #(some-> % (update-keys name)))))
604604

605605
(defn- generate-json! [out-file source-name]
606-
(let [conn (d/get-conn db-path bark-schema {:wal? false})]
606+
(let [conn (d/get-conn (db-path (load-config)) bark-schema {:wal? false})]
607607
(try
608608
(let [db (d/db conn)
609609
all-reps (all-reports db)

scripts/validate-config.clj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,9 @@
377377
;; Main
378378
;; ---------------------------------------------------------------------------
379379

380-
(let [path (or (first *command-line-args*) "config.edn")
380+
(let [path (or (first *command-line-args*)
381+
(System/getenv "BARK_CONFIG")
382+
"config.edn")
381383
file (clojure.java.io/file path)]
382384
(if-not (.exists file)
383385
(do (log/error "Config file not found:" path)

src/bark/common.clj

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -592,13 +592,23 @@
592592
;; ---------------------------------------------------------------------------
593593

594594
(defn load-config
595-
"Load config.edn if it exists, or nil."
596-
([] (load-config "config.edn"))
595+
"Load config.edn if it exists, or nil. With no args, consults the
596+
BARK_CONFIG env var, falling back to ./config.edn — so all bb
597+
scripts honor a single override point without per-script flags."
598+
([] (load-config (or (System/getenv "BARK_CONFIG") "config.edn")))
597599
([path]
598600
(let [f (io/file path)]
599601
(when (.exists f)
600602
(edn/read-string (slurp f))))))
601603

604+
(defn db-path
605+
"Resolve the Datalevin DB path: prefer :db {:path …} from the
606+
config, fall back to BARK_DB env var, then default \"data/bark-db\"."
607+
[config]
608+
(or (get-in config [:db :path])
609+
(System/getenv "BARK_DB")
610+
"data/bark-db"))
611+
602612
(defn build-source-map
603613
"Build source-name -> config map from config."
604614
[config]

src/bark/main.clj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,9 @@
557557
{:watch? (arg-set "--watch")
558558
:fresh? (arg-set "--fresh")
559559
:cli-fetch (some (fn [[a b]] (when (= "--fetch" a) b)) pairs)
560-
:config-path (or (some (fn [[a b]] (when (= "-c" a) b)) pairs) "config.edn")}))
560+
:config-path (or (some (fn [[a b]] (when (= "-c" a) b)) pairs)
561+
(System/getenv "BARK_CONFIG")
562+
"config.edn")}))
561563

562564
(defn- confirm-fresh! [db-path]
563565
(print (str "Wipe DB at " db-path "? [y/N] ")) (flush)

0 commit comments

Comments
 (0)