Fix --nimbledir for c command and separate flags into actions.

This commit is contained in:
Dominik Picheta 2016-12-22 14:38:22 +01:00
commit cb1248a9b4
2 changed files with 51 additions and 31 deletions

View file

@ -96,6 +96,10 @@ proc displayDebug*(category, msg: string) =
## Convenience for displaying debug messages. ## Convenience for displaying debug messages.
display(category, msg, priority = DebugPriority) display(category, msg, priority = DebugPriority)
proc displayDebug*(msg: string) =
## Convenience for displaying debug messages with a default category.
displayDebug("Debug:", msg)
proc displayTip*() = proc displayTip*() =
## Called just before Nimble exits. Shows some tips for the user, for example ## Called just before Nimble exits. Shows some tips for the user, for example
## the amount of messages that were suppressed and how to show them. ## the amount of messages that were suppressed and how to show them.

View file

@ -52,6 +52,7 @@ Usage: nimble COMMAND [opts]
Commands: Commands:
install [pkgname, ...] Installs a list of packages. install [pkgname, ...] Installs a list of packages.
[-d, --depsOnly] Install only dependencies.
init [pkgname] Initializes a new Nimble project. init [pkgname] Initializes a new Nimble project.
publish Publishes a package on nim-lang/packages. publish Publishes a package on nim-lang/packages.
The current working directory needs to be the The current working directory needs to be the
@ -62,9 +63,11 @@ Commands:
to the Nim compiler. to the Nim compiler.
refresh [url] Refreshes the package list. A package list URL refresh [url] Refreshes the package list. A package list URL
can be optionally specified. can be optionally specified.
search [--ver] pkg/tag Searches for a specified package. Search is search pkg/tag Searches for a specified package. Search is
performed by tag and by name. performed by tag and by name.
list [--ver] Lists all packages. [--ver] Query remote server for package version.
list Lists all packages.
[--ver] Query remote server for package version.
[-i, --installed] Lists all installed packages. [-i, --installed] Lists all installed packages.
tasks Lists the tasks specified in the Nimble tasks Lists the tasks specified in the Nimble
package's Nimble file. package's Nimble file.
@ -81,7 +84,6 @@ Options:
--ver Query remote server for package version --ver Query remote server for package version
information when searching or listing packages information when searching or listing packages
--nimbleDir dirname Set the Nimble directory. --nimbleDir dirname Set the Nimble directory.
-d --depsOnly Install only dependencies.
--verbose Show all non-debug output. --verbose Show all non-debug output.
--debug Show all output including debug messages. --debug Show all output including debug messages.
@ -99,15 +101,11 @@ proc writeVersion() =
quit(QuitSuccess) quit(QuitSuccess)
proc parseActionType*(action: string): ActionType = proc parseActionType*(action: string): ActionType =
case action.normalize()
of "install", "path":
case action.normalize() case action.normalize()
of "install": of "install":
result = actionInstall result = actionInstall
of "path": of "path":
result = actionPath result = actionPath
else:
discard
of "build": of "build":
result = actionBuild result = actionBuild
of "c", "compile", "js", "cpp", "cc": of "c", "compile", "js", "cpp", "cc":
@ -230,6 +228,34 @@ proc parseArgument*(key: string, result: var Options) =
discard discard
proc parseFlag*(flag, val: string, result: var Options) = proc parseFlag*(flag, val: string, result: var Options) =
var wasFlagHandled = true
# Global flags.
case flag.normalize()
of "help", "h": writeHelp()
of "version", "v": writeVersion()
of "accept", "y": result.forcePrompts = forcePromptYes
of "reject", "n": result.forcePrompts = forcePromptNo
of "nimbledir": result.nimbleDir = val
of "verbose": result.verbosity = LowPriority
of "debug": result.verbosity = DebugPriority
# 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:
case result.action.typ case result.action.typ
of actionCompile: of actionCompile:
if val == "": if val == "":
@ -239,19 +265,9 @@ proc parseFlag*(flag, val: string, result: var Options) =
of actionCustom: of actionCustom:
result.action.flags[flag] = val result.action.flags[flag] = val
else: else:
# TODO: These should not be global. wasFlagHandled = false
case flag.normalize()
of "help", "h": writeHelp() if not wasFlagHandled:
of "version", "v": writeVersion()
of "accept", "y": result.forcePrompts = forcePromptYes
of "reject", "n": result.forcePrompts = forcePromptNo
of "ver": result.queryVersions = true
of "nimbledir": result.nimbleDir = val
of "installed", "i": result.queryInstalled = true
of "depsonly", "d": result.depsOnly = true
of "verbose": result.verbosity = LowPriority
of "debug": result.verbosity = DebugPriority
else:
raise newException(NimbleError, "Unknown option: --" & flag) raise newException(NimbleError, "Unknown option: --" & flag)
proc initOptions*(): Options = proc initOptions*(): Options =