Skip to content

Commit

Permalink
refactor: avoid some chalkConfig field accesses
Browse files Browse the repository at this point in the history
  • Loading branch information
ee7 committed Mar 12, 2024
1 parent 3d4efd7 commit ed55b2e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
14 changes: 7 additions & 7 deletions src/confload.nim
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ proc findOptionalConf(state: ConfigState): Option[string] =

proc loadLocalStructs*(state: ConfigState) =
chalkConfig = state.attrs.loadChalkConfig()
if chalkConfig.color.isSome(): setShowColor(chalkConfig.color.get())
setLogLevel(chalkConfig.logLevel)
if getOpt[bool](chalkConfig, "color").isSome(): setShowColor(get[bool](chalkConfig, "color"))
setLogLevel(get[string](chalkConfig, "log_level"))
var configPath: seq[string] = @[]
for path in chalkConfig.configPath:
for path in get[seq[string]](chalkConfig, "config_path"):
try:
configPath.add(path.resolvePath())
except:
Expand All @@ -128,15 +128,15 @@ proc loadLocalStructs*(state: ConfigState) =
# and any logs are very verbose
continue
chalkConfig.configPath = configPath
var c4errLevel = if chalkConfig.con4mPinpoint: c4vShowLoc else: c4vBasic
var c4errLevel = if get[bool](chalkConfig, "con4m_pinpoint"): c4vShowLoc else: c4vBasic

if chalkConfig.chalkDebug:
if get[bool](chalkConfig, "chalk_debug"):
c4errLevel = if c4errLevel == c4vBasic: c4vTrace else: c4vMax

setCon4mVerbosity(c4errLevel)

proc handleCon4mErrors(err, tb: string): bool =
if tb != "" and chalkConfig == nil or chalkConfig.chalkDebug:
if tb != "" and chalkConfig == nil or get[bool](chalkConfig, "chalk_debug"):
echo formatCompilerError(err, nil, tb, default(InstInfo))
else:
error(err)
Expand Down Expand Up @@ -238,7 +238,7 @@ proc loadAllConfigs*() =
doRun()
hostInfo["_OP_CONFIG"] = pack(configFile)

if commandName == "not_supplied" and chalkConfig.defaultCommand.isSome():
if commandName == "not_supplied" and getOpt[string](chalkConfig, "default_command").isSome():
setErrorHandler(stack, handleOtherErrors)
addFinalizeGetOpts(stack, printAutoHelp = false)
addCallback(stack, loadLocalStructs)
Expand Down
4 changes: 2 additions & 2 deletions src/subscan.nim
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ proc runChalkSubScan*(location: seq[string],
cmd: string,
suspendHost = true): CollectionCtx =
let
oldRecursive = chalkConfig.recursive
oldRecursive = get[bool](chalkConfig, "recursive")
oldCmd = getCommandName()
oldArgs = getArgs()
logLevel = getLogLevel()
Expand All @@ -31,7 +31,7 @@ proc runChalkSubScan*(location: seq[string],

var savedLogLevel: Option[LogLevel]

if logLevel > llError and not chalkConfig.chalkDebug:
if logLevel > llError and not get[bool](chalkConfig, "chalk_debug"):
trace("*** Setting log-level = \"error\" for scan. Use --debug to turn on")
savedLogLevel = some(logLevel)
setLogLevel(llError)
Expand Down

0 comments on commit ed55b2e

Please sign in to comment.