Skip to content

Commit

Permalink
refactor(confload, subscan): remove chalkConfig field accesses (#237)
Browse files Browse the repository at this point in the history
Continue from past commits [1][2], removing every remaining access of a
ChalkConfig field whose type consists only of built-in types.

Refs: #214

[1] 66a5bb4, "refactor: begin to avoid autogenerated getters"
[2] 4157b58, "refactor: reduce usage of autogenerated getters, part 2"
  • Loading branch information
ee7 authored Jun 11, 2024
1 parent fa5e5da commit 855197e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
16 changes: 8 additions & 8 deletions src/confload.nim
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,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 @@ -98,16 +98,16 @@ proc loadLocalStructs*(state: ConfigState) =
# no log as this function is called multiple times
# and any logs are very verbose
continue
chalkConfig.configPath = configPath
var c4errLevel = if chalkConfig.con4mPinpoint: c4vShowLoc else: c4vBasic
doAssert state.attrSet("config_path", pack(configPath)).code == errOk
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 @@ -207,7 +207,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
9 changes: 5 additions & 4 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,15 +31,16 @@ 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)

let runtime = getChalkRuntime()
try:
if suspendHost:
suspendHostCollection()
chalkConfig.recursive = true
doAssert runtime.attrSet("recursive", pack(true)).code == errOk
result = pushCollectionCtx()
case cmd
# if someone is doing 'docker' recursively, we look
Expand All @@ -59,7 +60,7 @@ proc runChalkSubScan*(location: seq[string],
setCommandName(oldCmd)
setArgs(oldArgs)
trace("Subscan done. Restored command name to: " & oldCmd)
chalkConfig.recursive = oldRecursive
doAssert runtime.attrSet("recursive", pack(oldRecursive)).code == errOk

template runChalkSubScan*(location: string,
cmd: string,
Expand Down

0 comments on commit 855197e

Please sign in to comment.