This commit is contained in:
Andrea Ferretti 2017-04-07 15:09:13 +02:00
commit 2e9c50e487
2 changed files with 27 additions and 22 deletions

View file

@ -235,11 +235,12 @@ proc parseArgument*(key: string, result: var Options) =
else: else:
discard discard
proc parseFlag*(flag, val: string, result: var Options) = proc parseFlag*(flag, val: string, result: var Options, kind = cmdLongOption) =
var wasFlagHandled = true var wasFlagHandled = true
let f = flag.normalize()
# Global flags. # Global flags.
case flag.normalize() case f
of "help", "h": writeHelp() of "help", "h": writeHelp()
of "version", "v": writeVersion() of "version", "v": writeVersion()
of "accept", "y": result.forcePrompts = forcePromptYes of "accept", "y": result.forcePrompts = forcePromptYes
@ -248,28 +249,28 @@ proc parseFlag*(flag, val: string, result: var Options) =
of "verbose": result.verbosity = LowPriority of "verbose": result.verbosity = LowPriority
of "debug": result.verbosity = DebugPriority of "debug": result.verbosity = DebugPriority
# Action-specific flags. # Action-specific flags.
of "installed", "i":
if result.action.typ in [actionSearch, actionList]:
result.queryInstalled = true
else:
wasFlagHandled = false
of "depsonly", "d":
if result.action.typ == actionInstall:
result.depsOnly = true
else:
wasFlagHandled = false
of "ver":
if result.action.typ in [actionSearch, actionList]:
result.queryVersions = true
else:
wasFlagHandled = false
else: else:
case result.action.typ case result.action.typ
of actionCompile, actionDoc: of actionSearch, actionList:
if val == "": case f
result.action.compileOptions.add("--" & flag) of "installed", "i":
result.queryInstalled = true
of "ver":
result.queryVersions = true
else: else:
result.action.compileOptions.add("--" & flag & ":" & val) wasFlagHandled = false
of actionInstall:
case f
of "depsonly", "d":
result.depsOnly = true
else:
wasFlagHandled = false
of actionCompile, actionDoc:
let prefix = if kind == cmdShortOption: "-" else: "--"
if val == "":
result.action.compileOptions.add(prefix & flag)
else:
result.action.compileOptions.add(prefix & flag & ":" & val)
of actionCustom: of actionCustom:
result.action.flags[flag] = val result.action.flags[flag] = val
else: else:
@ -310,7 +311,7 @@ proc parseCmdLine*(): Options =
else: else:
parseArgument(key, result) parseArgument(key, result)
of cmdLongOption, cmdShortOption: of cmdLongOption, cmdShortOption:
parseFlag(key, val, result) parseFlag(key, val, result, kind)
of cmdEnd: assert(false) # cannot happen of cmdEnd: assert(false) # cannot happen
# Set verbosity level. # Set verbosity level.

View file

@ -52,6 +52,10 @@ test "can distinguish package reading in nimbleDir vs. other dirs (#304)":
cd "issue304" / "package-test": cd "issue304" / "package-test":
check execNimble("tasks").exitCode == QuitSuccess check execNimble("tasks").exitCode == QuitSuccess
test "can accept short flags (#329)":
cd "nimscript":
check execNimble("c", "-d:release", "nimscript.nim").exitCode == QuitSuccess
test "can build with #head and versioned package (#289)": test "can build with #head and versioned package (#289)":
cd "issue289": cd "issue289":
check execNimble(["install", "-y"]).exitCode == QuitSuccess check execNimble(["install", "-y"]).exitCode == QuitSuccess