Allow doAction to show help/version instead of CLI parser.

This commit is contained in:
Dominik Picheta 2017-04-28 16:52:34 +02:00
commit c1ffe62a68
2 changed files with 14 additions and 8 deletions

View file

@ -988,6 +988,11 @@ proc execHook(options: Options, before: bool): bool =
result = res.retVal result = res.retVal
proc doAction(options: Options) = proc doAction(options: Options) =
if options.showHelp:
writeHelp()
if options.showVersion:
writeVersion()
if not existsDir(options.getNimbleDir()): if not existsDir(options.getNimbleDir()):
createDir(options.getNimbleDir()) createDir(options.getNimbleDir())
if not existsDir(options.getPkgsDir): if not existsDir(options.getPkgsDir):

View file

@ -18,6 +18,8 @@ type
config*: Config config*: Config
nimbleData*: JsonNode ## Nimbledata.json nimbleData*: JsonNode ## Nimbledata.json
pkgInfoCache*: TableRef[string, PackageInfo] pkgInfoCache*: TableRef[string, PackageInfo]
showHelp*: bool
showVersion*: bool
ActionType* = enum ActionType* = enum
actionNil, actionRefresh, actionInit, actionDump, actionPublish, actionNil, actionRefresh, actionInit, actionDump, actionPublish,
@ -45,7 +47,6 @@ type
arguments*: seq[string] arguments*: seq[string]
flags*: StringTableRef flags*: StringTableRef
const const
help* = """ help* = """
Usage: nimble COMMAND [opts] Usage: nimble COMMAND [opts]
@ -88,7 +89,7 @@ Options:
-n, --reject Reject all interactive prompts. -n, --reject Reject all interactive prompts.
--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.
--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.
@ -101,7 +102,7 @@ proc writeHelp*(quit=true) =
if quit: if quit:
raise NimbleQuit(msg: "") raise NimbleQuit(msg: "")
proc writeVersion() = proc writeVersion*() =
echo("nimble v$# compiled at $# $#" % echo("nimble v$# compiled at $# $#" %
[nimbleVersion, CompileDate, CompileTime]) [nimbleVersion, CompileDate, CompileTime])
raise NimbleQuit(msg: "") raise NimbleQuit(msg: "")
@ -229,7 +230,7 @@ proc parseArgument*(key: string, result: var Options) =
of actionCompile, actionDoc: of actionCompile, actionDoc:
result.action.file = key result.action.file = key
of actionList, actionBuild, actionPublish: of actionList, actionBuild, actionPublish:
writeHelp() result.showHelp = true
of actionCustom: of actionCustom:
result.action.arguments.add(key) result.action.arguments.add(key)
else: else:
@ -241,8 +242,8 @@ proc parseFlag*(flag, val: string, result: var Options, kind = cmdLongOption) =
# Global flags. # Global flags.
case f case f
of "help", "h": writeHelp() of "help", "h": result.showHelp = true
of "version", "v": writeVersion() of "version", "v": result.showVersion = true
of "accept", "y": result.forcePrompts = forcePromptYes of "accept", "y": result.forcePrompts = forcePromptYes
of "reject", "n": result.forcePrompts = forcePromptNo of "reject", "n": result.forcePrompts = forcePromptNo
of "nimbledir": result.nimbleDir = val of "nimbledir": result.nimbleDir = val
@ -323,8 +324,8 @@ proc parseCmdLine*(): Options =
# Parse other things, for example the nimbledata.json file. # Parse other things, for example the nimbledata.json file.
parseMisc(result) parseMisc(result)
if result.action.typ == actionNil: if result.action.typ == actionNil and not result.showVersion:
writeHelp() result.showHelp = true
proc getProxy*(options: Options): Proxy = proc getProxy*(options: Options): Proxy =
## Returns ``nil`` if no proxy is specified. ## Returns ``nil`` if no proxy is specified.