fix: ensure nimble file exists before reading

This commit is contained in:
Daylin Morgan 2023-09-28 13:46:21 -05:00
parent 42edeb0726
commit 19919e1dd9
Signed by: daylin
GPG key ID: C1E52E7DD81DF79F

View file

@ -1,7 +1,7 @@
import std/[parsecfg, tables, os, strutils, strformat] import std/[parsecfg, tables, os, strutils, strformat]
type type
Config* = object ForgeConfig* = object
targets*: OrderedTableRef[string, string] targets*: OrderedTableRef[string, string]
bins*: OrderedTableRef[string, string] bins*: OrderedTableRef[string, string]
outdir*: string outdir*: string
@ -10,7 +10,7 @@ type
version*: string version*: string
nimble*: bool nimble*: bool
proc `$`*(c: Config): string = proc `$`*(c: ForgeConfig): string =
var lines: seq[string] = @[] var lines: seq[string] = @[]
lines.add "config =" lines.add "config ="
lines.add "| nimble " & $c.nimble lines.add "| nimble " & $c.nimble
@ -26,7 +26,8 @@ proc `$`*(c: Config): string =
lines.join("\n") lines.join("\n")
proc loadConfigFile*(f: string, load_targets: bool, load_bins: bool): Config = proc loadConfigFile*(f: string, load_targets: bool,
load_bins: bool): ForgeConfig =
let let
dict = loadConfig(f) dict = loadConfig(f)
base = dict.getOrDefault("") base = dict.getOrDefault("")
@ -70,7 +71,7 @@ proc findNimbleFile(): string =
proc inferVersion(s: string, nimbleFile: string): string = proc inferVersion(s: string, nimbleFile: string): string =
if s != "": return s if s != "": return s
# TODO: catch io errors? if nimbleFile.fileExists:
let nimbleCfg = loadConfig(nimbleFile) let nimbleCfg = loadConfig(nimbleFile)
return nimbleCfg.getSectionValue("", "version") return nimbleCfg.getSectionValue("", "version")
@ -94,7 +95,7 @@ proc newConfig*(
nimble: bool, nimble: bool,
configFile: string, configFile: string,
noConfig: bool noConfig: bool
): Config = ): ForgeConfig =
let nimbleFile = findNimbleFile() let nimbleFile = findNimbleFile()