Change default value logic for stepCmd and cmdInput (see README).

This commit is contained in:
Jonathan Bernard
2017-05-11 10:38:28 -05:00
parent 45f490c677
commit a7619a3048
3 changed files with 15 additions and 5 deletions

View File

@ -146,15 +146,25 @@ proc loadProjectConfig*(cfgFile: string): ProjectConfig =
steps[sName] = Step(
name: sName,
workingDir: pJson.getIfExists("workingDir").getStr("."),
stepCmd: pJson.getIfExists("stepCmd").getStr("sh"),
stepCmd: pJson.getIfExists("stepCmd").getStr("NOT GIVEN"),
depends: pJson.getIfExists("depends").getElems.mapIt(it.getStr),
artifacts: pJson.getIfExists("artifacts").getElems.mapIt(it.getStr),
cmdInput: pJson.getIfExists("cmdInput").getElems.mapIt(it.getStr),
expectedEnv: pJson.getIfExists("expectedEnv").getElems.mapIt(it.getStr),
dontSkip: pJson.getIfExists("dontSkip").getBVal(false))
if steps[sName].stepCmd == "sh" and steps[sName].cmdInput.len == 0:
warn "Step " & sName & " uses 'sh' as its command but has no cmdInput."
# cmdInput and stepCmd are related, so we have a conditional defaulting.
# Four possibilities:
if steps[sName].stepCmd == "NOT GIVEN" and steps[sName].cmdInput.len == 0:
# 1. Neither given: default to no-op
steps[sName].stepCmd = "true"
if steps[sName].stepCmd == "NOT GIVEN" and steps[sName].cmdInput.len > 0:
# 2. cmdInput given but not stepCmd: default stepCmd to "sh"
steps[sName].stepCmd = "sh"
# 3. stepCmd given but not cmdInput & 4. both given: use them as-is
result = ProjectConfig(
name: jsonCfg.getOrFail("name", "project configuration").getStr,