import std/[nativesockets, options] import std/[parsecfg, parseutils, strutils] import threadvars, types proc parseConfig* (configFile: string): types.Config = try: let config = loadConfig(configFile) if config.getSectionValue("server", "Port") != "": result.ServerPort = Port(config.getSectionValue("server", "Port").parseInt) else: result.ServerPort = Port(8080) if config.getSectionValue("server", "accessToken") != "": result.ServerAccessToken = some(config.getSectionValue("server", "accessToken")) if config.getSectionValue("travelynx", "username") != "": result.TravelynxuserName = some(config.getSectionValue("travelynx", "username")) if config.getSectionValue("fedi", "url") != "": result.FediURL = config.getSectionValue("fedi", "url") else: echo "Configparser: [fedi]url not specified!" quit(1) if config.getSectionValue("fedi", "accessToken") != "": result.FediAccessToken = config.getSectionValue("fedi", "accessToken") else: echo "Configparser: [fedi]accessToken not specified!" quit(1) if config.getSectionValue("fedi", "visibility") != "": result.FediVisibility = some(parseEnum[PostVisibility](config.getSectionValue("fedi", "visibility"))) if config.getSectionValue("fedi", "spoilerText") != "": result.FediSpoilerText = some(config.getSectionValue("fedi", "spoilerText")) if config.getSectionValue("fedi", "useMarkdown") != "": result.FediUseMarkdown = config.getSectionValue("fedi", "useMarkdown").parseBool else: result.FediUseMarkdown = false except CatchableError: let e = getCurrentException() msg = getCurrentExceptionMsg() echo "Couldn't parse config file:" echo "Got exception ", repr(e), " with message ", msg