Parse command line args first so that -v doesn't read config.
This commit is contained in:
parent
3c22ffd848
commit
abb9d79ea4
2 changed files with 26 additions and 19 deletions
|
|
@ -10,7 +10,8 @@ from sequtils import toSeq
|
||||||
|
|
||||||
import nimblepkg/packageinfo, nimblepkg/version, nimblepkg/tools,
|
import nimblepkg/packageinfo, nimblepkg/version, nimblepkg/tools,
|
||||||
nimblepkg/download, nimblepkg/config, nimblepkg/common,
|
nimblepkg/download, nimblepkg/config, nimblepkg/common,
|
||||||
nimblepkg/publish, nimblepkg/options, nimblepkg/packageparser
|
nimblepkg/publish, nimblepkg/options, nimblepkg/packageparser,
|
||||||
|
nimblepkg/cli
|
||||||
|
|
||||||
import nimblepkg/nimscriptsupport
|
import nimblepkg/nimscriptsupport
|
||||||
|
|
||||||
|
|
@ -32,11 +33,6 @@ else:
|
||||||
proc GetVersionExA*(VersionInformation: var OSVERSIONINFO): WINBOOL{.stdcall,
|
proc GetVersionExA*(VersionInformation: var OSVERSIONINFO): WINBOOL{.stdcall,
|
||||||
dynlib: "kernel32", importc: "GetVersionExA".}
|
dynlib: "kernel32", importc: "GetVersionExA".}
|
||||||
|
|
||||||
proc writeVersion() =
|
|
||||||
echo("nimble v$# compiled at $# $#" %
|
|
||||||
[nimbleVersion, CompileDate, CompileTime])
|
|
||||||
quit(QuitSuccess)
|
|
||||||
|
|
||||||
proc promptCustom(question, default: string): string =
|
proc promptCustom(question, default: string): string =
|
||||||
if default == "":
|
if default == "":
|
||||||
stdout.write(question, ": ")
|
stdout.write(question, ": ")
|
||||||
|
|
@ -961,8 +957,6 @@ proc doAction(options: Options) =
|
||||||
dump(options)
|
dump(options)
|
||||||
of actionTasks:
|
of actionTasks:
|
||||||
listTasks(options)
|
listTasks(options)
|
||||||
of actionVersion:
|
|
||||||
writeVersion()
|
|
||||||
of actionNil:
|
of actionNil:
|
||||||
assert false
|
assert false
|
||||||
of actionCustom:
|
of actionCustom:
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ type
|
||||||
depsOnly*: bool
|
depsOnly*: bool
|
||||||
queryVersions*: bool
|
queryVersions*: bool
|
||||||
queryInstalled*: bool
|
queryInstalled*: bool
|
||||||
|
nimbleDir*: string
|
||||||
action*: Action
|
action*: Action
|
||||||
config*: Config
|
config*: Config
|
||||||
nimbleData*: JsonNode ## Nimbledata.json
|
nimbleData*: JsonNode ## Nimbledata.json
|
||||||
|
|
@ -21,12 +22,11 @@ type
|
||||||
actionNil, actionRefresh, actionInit, actionDump, actionPublish,
|
actionNil, actionRefresh, actionInit, actionDump, actionPublish,
|
||||||
actionInstall, actionSearch,
|
actionInstall, actionSearch,
|
||||||
actionList, actionBuild, actionPath, actionUninstall, actionCompile,
|
actionList, actionBuild, actionPath, actionUninstall, actionCompile,
|
||||||
actionCustom, actionTasks, actionVersion
|
actionCustom, actionTasks
|
||||||
|
|
||||||
Action* = object
|
Action* = object
|
||||||
case typ*: ActionType
|
case typ*: ActionType
|
||||||
of actionNil, actionList, actionBuild, actionPublish, actionTasks,
|
of actionNil, actionList, actionBuild, actionPublish, actionTasks: nil
|
||||||
actionVersion: nil
|
|
||||||
of actionRefresh:
|
of actionRefresh:
|
||||||
optionalURL*: string # Overrides default package list.
|
optionalURL*: string # Overrides default package list.
|
||||||
of actionInstall, actionPath, actionUninstall:
|
of actionInstall, actionPath, actionUninstall:
|
||||||
|
|
@ -93,6 +93,11 @@ proc writeHelp*() =
|
||||||
echo(help)
|
echo(help)
|
||||||
quit(QuitSuccess)
|
quit(QuitSuccess)
|
||||||
|
|
||||||
|
proc writeVersion() =
|
||||||
|
echo("nimble v$# compiled at $# $#" %
|
||||||
|
[nimbleVersion, CompileDate, CompileTime])
|
||||||
|
quit(QuitSuccess)
|
||||||
|
|
||||||
proc parseActionType*(action: string): ActionType =
|
proc parseActionType*(action: string): ActionType =
|
||||||
case action.normalize()
|
case action.normalize()
|
||||||
of "install", "path":
|
of "install", "path":
|
||||||
|
|
@ -153,7 +158,7 @@ proc initAction*(options: var Options, key: string) =
|
||||||
options.action.arguments = @[]
|
options.action.arguments = @[]
|
||||||
options.action.flags = newStringTable()
|
options.action.flags = newStringTable()
|
||||||
of actionBuild, actionPublish, actionList, actionTasks,
|
of actionBuild, actionPublish, actionList, actionTasks,
|
||||||
actionNil, actionVersion: discard
|
actionNil: discard
|
||||||
|
|
||||||
proc prompt*(options: Options, question: string): bool =
|
proc prompt*(options: Options, question: string): bool =
|
||||||
## Asks an interactive question and returns the result.
|
## Asks an interactive question and returns the result.
|
||||||
|
|
@ -191,7 +196,13 @@ proc renameBabelToNimble(options: Options) {.deprecated.} =
|
||||||
removeFile(nimbleDir / "babeldata.json")
|
removeFile(nimbleDir / "babeldata.json")
|
||||||
|
|
||||||
proc getNimbleDir*(options: Options): string =
|
proc getNimbleDir*(options: Options): string =
|
||||||
expandTilde(options.config.nimbleDir)
|
result =
|
||||||
|
if options.nimbleDir.len == 0:
|
||||||
|
options.config.nimbleDir
|
||||||
|
else:
|
||||||
|
options.nimbleDir
|
||||||
|
|
||||||
|
return expandTilde(result)
|
||||||
|
|
||||||
proc getPkgsDir*(options: Options): string =
|
proc getPkgsDir*(options: Options): string =
|
||||||
options.getNimbleDir() / "pkgs"
|
options.getNimbleDir() / "pkgs"
|
||||||
|
|
@ -247,13 +258,11 @@ proc parseFlag*(flag, val: string, result: var Options) =
|
||||||
# TODO: These should not be global.
|
# TODO: These should not be global.
|
||||||
case flag.normalize()
|
case flag.normalize()
|
||||||
of "help", "h": writeHelp()
|
of "help", "h": writeHelp()
|
||||||
of "version", "v":
|
of "version", "v": writeVersion()
|
||||||
assert result.action.typ == actionNil
|
|
||||||
result.action.typ = actionVersion
|
|
||||||
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 "ver": result.queryVersions = true
|
of "ver": result.queryVersions = true
|
||||||
of "nimbledir": result.config.nimbleDir = val # overrides option from file
|
of "nimbledir": result.nimbleDir = val
|
||||||
of "installed", "i": result.queryInstalled = true
|
of "installed", "i": result.queryInstalled = true
|
||||||
of "depsonly", "d": result.depsOnly = true
|
of "depsonly", "d": result.depsOnly = true
|
||||||
else:
|
else:
|
||||||
|
|
@ -262,6 +271,7 @@ proc parseFlag*(flag, val: string, result: var Options) =
|
||||||
proc initOptions*(): Options =
|
proc initOptions*(): Options =
|
||||||
result.action.typ = actionNil
|
result.action.typ = actionNil
|
||||||
result.pkgInfoCache = newTable[string, PackageInfo]()
|
result.pkgInfoCache = newTable[string, PackageInfo]()
|
||||||
|
result.nimbleDir = ""
|
||||||
|
|
||||||
proc parseMisc(options: var Options) =
|
proc parseMisc(options: var Options) =
|
||||||
# Load nimbledata.json
|
# Load nimbledata.json
|
||||||
|
|
@ -278,9 +288,9 @@ proc parseMisc(options: var Options) =
|
||||||
|
|
||||||
proc parseCmdLine*(): Options =
|
proc parseCmdLine*(): Options =
|
||||||
result = initOptions()
|
result = initOptions()
|
||||||
result.config = parseConfig()
|
|
||||||
|
|
||||||
# Parse command line params.
|
# Parse command line params first. A simple `--version` shouldn't require
|
||||||
|
# a config to be parsed.
|
||||||
for kind, key, val in getOpt():
|
for kind, key, val in getOpt():
|
||||||
case kind
|
case kind
|
||||||
of cmdArgument:
|
of cmdArgument:
|
||||||
|
|
@ -292,6 +302,9 @@ proc parseCmdLine*(): Options =
|
||||||
parseFlag(key, val, result)
|
parseFlag(key, val, result)
|
||||||
of cmdEnd: assert(false) # cannot happen
|
of cmdEnd: assert(false) # cannot happen
|
||||||
|
|
||||||
|
# Parse config.
|
||||||
|
result.config = parseConfig()
|
||||||
|
|
||||||
# Parse other things, for example the nimbledata.json file.
|
# Parse other things, for example the nimbledata.json file.
|
||||||
parseMisc(result)
|
parseMisc(result)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue