 (ns brainbot.nozzle.sys
+  "system map creation and a bit of iniconfig utils"
   (:require [brainbot.nozzle.worker :as worker]
             [brainbot.nozzle.misc :as misc]
             [brainbot.nozzle.inihelper :as inihelper]

  (:import [java.util.concurrent Executors]))

(defn valid-name?
  "check if s is a valid-name"
  [s]
  (boolean (re-matches #"^[-a-zA-Z0-9_]+$" s)))


  current-system nil)

(defn run-system
  "start running the system by starting a meta-runner with the
  command-sections"
  [{:keys [iniconfig command-sections] :as system}]
  (alter-var-root #'current-system (constantly system))
  (worker/start (meta-runner/make-meta-runner system command-sections)))

(defn- get-filesystems-for-section*
  "get filesystems specified in section and validate them. no fallback"
  [system section-name]
  (let [filesystems (misc/trimmed-lines-from-string
                     (get-in system [:iniconfig section-name "filesystems"]))
        die (make-die-fn (:iniconfig system) section-name)]
    (validate-filesystems filesystems die)
    filesystems))

(defn get-filesystems-for-section
  "get the list of filesystem names specified in the given section or
  as a fallback in the main section"
  [system section-name]
  (or (get-filesystems-for-section* system section-name)
      (get-in system [:config :filesystems])
      (inidie (:iniconfig system) section-name "no filesystems defined")))
