2024-09-13 12:29:41 -05:00
|
|
|
import std/[os, streams, strformat, strutils]
|
|
|
|
import yaml
|
|
|
|
import term
|
2024-03-18 16:19:42 -05:00
|
|
|
|
|
|
|
type
|
2024-03-18 16:43:38 -05:00
|
|
|
TsmConfig* = object
|
|
|
|
dirs*: seq[string]
|
|
|
|
sessions*: seq[Session]
|
2024-03-18 16:19:42 -05:00
|
|
|
|
|
|
|
Session = object
|
2024-03-18 16:43:38 -05:00
|
|
|
name*, dir*: string
|
2024-03-18 16:19:42 -05:00
|
|
|
|
|
|
|
proc loadConfigFile(): TsmConfig =
|
2024-09-13 12:29:41 -05:00
|
|
|
let configPath = getEnv("TSM_CONFIG", getConfigDir() / "tsm" / "config.yml")
|
|
|
|
try:
|
|
|
|
var s = newFileStream(configPath)
|
|
|
|
load(s, result)
|
|
|
|
s.close()
|
|
|
|
except:
|
|
|
|
termError fmt(
|
|
|
|
"failed to load config file\npath: {configPath}\nmessage: {getCurrentExceptionMsg()}"
|
|
|
|
)
|
2024-03-18 16:19:42 -05:00
|
|
|
|
2024-03-18 16:43:38 -05:00
|
|
|
proc loadTsmConfig*(): TsmConfig =
|
2024-03-18 16:19:42 -05:00
|
|
|
result = loadConfigFile()
|
|
|
|
let tsmDirs = getEnv("TSM_DIRS")
|
|
|
|
if tsmDirs != "":
|
|
|
|
result.dirs = tsmDirs.split(":")
|
|
|
|
|
|
|
|
when isMainModule:
|
2024-03-19 11:57:34 -05:00
|
|
|
echo loadConfigFile()
|