From 2009b16eb16320c6663cd6d53c74b36d09a89460 Mon Sep 17 00:00:00 2001 From: Daylin Morgan Date: Thu, 7 Sep 2023 17:08:56 -0500 Subject: [PATCH] fix: if args are given ignore config file for targets/bin --- src/forge.nim | 13 +++++++++---- src/forge/config.nim | 29 +++++++++++++++-------------- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/forge.nim b/src/forge.nim index d05d4d2..281342c 100644 --- a/src/forge.nim +++ b/src/forge.nim @@ -50,6 +50,7 @@ proc release( dryrun: bool = false, nimble: bool = false, configFile: string = ".forge.cfg", + noConfig: bool = false, verbose: bool = false, ) = ## generate release assets for n>=1 targets @@ -61,7 +62,7 @@ proc release( ## ## if name or version are not specified they will be inferred from the local .nimble file - var cfg = newConfig( + let cfg = newConfig( target, bin, outdir, @@ -69,8 +70,10 @@ proc release( name, version, nimble, - configFile + configFile, + noConfig ) + if cfg.targets.len == 0: termErrQuit "expected at least 1 target" if cfg.bins.len == 0: @@ -114,7 +117,8 @@ proc release( termEcho styleBright, "cmd: ", ansiResetCode, cmd let errCode = execCmd cmd if errCode != 0: - termErrQuit "problems executing cmd " & cmd + termErr "cmd: ", cmd + termErrQuit &"exited with code {errCode} see above for error" when isMainModule: import cligen @@ -148,7 +152,8 @@ when isMainModule: "dryrun": "show command instead of executing", "format": "set format, see help above", "nimble": "use nimble as base command for compiling", - "config-file": "path to config" + "config-file": "path to config", + "no-config": "ignore config file" }, short = {"verbose": 'V'} ] diff --git a/src/forge/config.nim b/src/forge/config.nim index 3908255..83511cf 100644 --- a/src/forge/config.nim +++ b/src/forge/config.nim @@ -26,7 +26,7 @@ proc `$`*(c: Config): string = lines.join("\n") -proc loadConfigFile*(f: string): Config = +proc loadConfigFile*(f: string, load_targets: bool, load_bins: bool): Config = let dict = loadConfig(f) base = dict.getOrDefault("") @@ -39,9 +39,9 @@ proc loadConfigFile*(f: string): Config = result.name = base.getOrDefault("name") result.version = base.getOrDefault("version") result.format = base.getOrDefault("format") - if dict.hasKey("target"): + if dict.hasKey("target") and load_targets: result.targets = dict.getOrDefault("target") - if dict.hasKey("bin"): + if dict.hasKey("bin") and load_bins: result.bins = dict.getOrDefault("bin") proc inferName(s: string, nimbleFile: string): string = @@ -85,20 +85,21 @@ proc inferBin(nimbleFile: string): string = proc newConfig*( - targets: seq[string], - bins: seq[string], - outdir: string, - format: string, - name: string, - version: string, - nimble: bool, - configFile: string - ): Config = + targets: seq[string], + bins: seq[string], + outdir: string, + format: string, + name: string, + version: string, + nimble: bool, + configFile: string, + noConfig: bool + ): Config = let nimbleFile = findNimbleFile() - if configFile.fileExists: - result = loadConfigFile(configFile) + if configFile.fileExists and not noConfig: + result = loadConfigFile(configFile, targets.len == 0, bins.len == 0) else: # no seg faults here... result.targets = newOrderedTable[string, string]()