Refactor utils out into cliutils package.
This commit is contained in:
@ -1,5 +1,4 @@
|
||||
import logging, json, os, nre, sequtils, strtabs, tables, times, uuids
|
||||
import private/util
|
||||
import cliutils, logging, json, os, nre, sequtils, strtabs, tables, times, uuids
|
||||
|
||||
from langutils import sameContents
|
||||
from typeinfo import toAny
|
||||
@ -96,6 +95,10 @@ proc setProject*(cfg: var StrawBossConfig, projectName: string, newDef: ProjectD
|
||||
|
||||
if not found: cfg.projects.add(newDef)
|
||||
|
||||
# other utils
|
||||
proc raiseEx*(reason: string): void =
|
||||
raise newException(Exception, reason)
|
||||
|
||||
# internal utils
|
||||
let nullNode = newJNull()
|
||||
proc getIfExists(n: JsonNode, key: string): JsonNode =
|
||||
@ -245,17 +248,3 @@ proc `$`*(s: BuildStatus): string = result = pretty(%s)
|
||||
proc `$`*(req: RunRequest): string = result = pretty(%req)
|
||||
proc `$`*(pd: ProjectDef): string = result = pretty(%pd)
|
||||
proc `$`*(cfg: StrawBossConfig): string = result = pretty(%cfg)
|
||||
|
||||
# TODO: maybe a macro for more general-purpose, shallow object comparison?
|
||||
#proc `==`*(a, b: ProjectDef): bool =
|
||||
|
||||
template shallowEquals(a, b: RootObj): bool =
|
||||
if type(a) != type(b): return false
|
||||
var anyB = toAny(b)
|
||||
|
||||
for name, value in a.fieldPairs:
|
||||
if value != b[name]: return false
|
||||
|
||||
return true
|
||||
|
||||
#proc `==`*(a, b: ProjectDef): bool = result = shallowEquals(a, b)
|
||||
|
Reference in New Issue
Block a user