From 6391e115d1a26f2be7133cfe46f3d9876bb1f5db Mon Sep 17 00:00:00 2001 From: Felisp Date: Sun, 28 Jul 2024 18:26:38 +0200 Subject: [PATCH] Copy global boards-defaults to every board-config --- src/rss_thread_watch/core.clj | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/src/rss_thread_watch/core.clj b/src/rss_thread_watch/core.clj index f14cd61..ee96881 100644 --- a/src/rss_thread_watch/core.clj +++ b/src/rss_thread_watch/core.clj @@ -57,19 +57,15 @@ (edn/read (java.io.PushbackReader. r)))))) (defn config-fill-board-defaults - "Fills every enabled board with default values" - [conifg] - ;; Získat všechny klíče desek které musíme vyplnit - ;; Každý klíč mergnout s default mapou - (u/map-apply-defaults ) - (let [board-defaults (:boards-default config) - boards (keys (:boards-enabled config))] - (update-in config '(:boards-enabled) (fn [val] - (u/fmap (fn []) - val) ) - ;; just do fmap of boards - ()) - ) + "Fills every enabled board with default config values" + [config] + (let [defaults (:boards-defaults config)] + (update-in config + '(:boards-enabled) + (fn [mp] + (u/fmap (fn [k v] + (u/map-apply-defaults v defaults)) + mp))))) (defn get-some-config "Attempts to get config somehow, @@ -79,13 +75,12 @@ ;; args do not include path to executable so first arg ;; should be config file [cmd-args] - (let [file-to-try (u/nil?-else (first cmd-args) + (config-fill-board-defaults + (let [file-to-try (u/nil?-else (first cmd-args) "./config.edn")] (u/when-else (load-config file-to-try) (println "WARN: Using default internal config because suggessted file: '" file-to-try "' not found.") - CONFIG-DEFAULT))) -;;TODO: We want to copy default board-local config into every board, that way we won't have to always look -;; into defaults, but + CONFIG-DEFAULT)))) ;; Todo: Add option to write default config to stdout (defn -main