mirror of
https://github.com/daylinmorgan/forge.git
synced 2024-11-24 00:40:45 -06:00
fix: ensure nimble file exists before reading
This commit is contained in:
parent
42edeb0726
commit
19919e1dd9
1 changed files with 8 additions and 7 deletions
|
@ -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()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue