Add findProject for looking up projects from the StrawBossConfig object properly.

This commit is contained in:
Jonathan Bernard
2017-04-25 12:54:08 -05:00
parent 81674dfa3f
commit 9d00d638db
2 changed files with 12 additions and 5 deletions

View File

@ -56,6 +56,15 @@ proc `==`*(a, b: ProjectDef): bool =
a.defaultBranch == b.defaultBranch and
a.repo == b.repo
# Util methods on custom types
proc findProject*(cfg: StrawBossConfig, projectName: string): ProjectDef =
let candidates = cfg.projects.filterIt(it.name == projectName)
if candidates.len == 0:
raise newException(KeyError, "no project named " & projectName)
elif candidates.len > 0:
raise newException(KeyError, "multiple projects named " & projectName)
else: result = candidates[0]
# internal utils
let nullNode = newJNull()