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,
|
||||
nimblepkg/download, nimblepkg/config, nimblepkg/common,
|
||||
nimblepkg/publish, nimblepkg/options, nimblepkg/packageparser
|
||||
nimblepkg/publish, nimblepkg/options, nimblepkg/packageparser,
|
||||
nimblepkg/cli
|
||||
|
||||
import nimblepkg/nimscriptsupport
|
||||
|
||||
|
|
@ -32,11 +33,6 @@ else:
|
|||
proc GetVersionExA*(VersionInformation: var OSVERSIONINFO): WINBOOL{.stdcall,
|
||||
dynlib: "kernel32", importc: "GetVersionExA".}
|
||||
|
||||
proc writeVersion() =
|
||||
echo("nimble v$# compiled at $# $#" %
|
||||
[nimbleVersion, CompileDate, CompileTime])
|
||||
quit(QuitSuccess)
|
||||
|
||||
proc promptCustom(question, default: string): string =
|
||||
if default == "":
|
||||
stdout.write(question, ": ")
|
||||
|
|
@ -961,8 +957,6 @@ proc doAction(options: Options) =
|
|||
dump(options)
|
||||
of actionTasks:
|
||||
listTasks(options)
|
||||
of actionVersion:
|
||||
writeVersion()
|
||||
of actionNil:
|
||||
assert false
|
||||
of actionCustom:
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ type
|
|||
depsOnly*: bool
|
||||
queryVersions*: bool
|
||||
queryInstalled*: bool
|
||||
nimbleDir*: string
|
||||
action*: Action
|
||||
config*: Config
|
||||
nimbleData*: JsonNode ## Nimbledata.json
|
||||
|
|
@ -21,12 +22,11 @@ type
|
|||
actionNil, actionRefresh, actionInit, actionDump, actionPublish,
|
||||
actionInstall, actionSearch,
|
||||
actionList, actionBuild, actionPath, actionUninstall, actionCompile,
|
||||
actionCustom, actionTasks, actionVersion
|
||||
actionCustom, actionTasks
|
||||
|
||||
Action* = object
|
||||
case typ*: ActionType
|
||||
of actionNil, actionList, actionBuild, actionPublish, actionTasks,
|
||||
actionVersion: nil
|
||||
of actionNil, actionList, actionBuild, actionPublish, actionTasks: nil
|
||||
of actionRefresh:
|
||||
optionalURL*: string # Overrides default package list.
|
||||
of actionInstall, actionPath, actionUninstall:
|
||||
|
|
@ -93,6 +93,11 @@ proc writeHelp*() =
|
|||
echo(help)
|
||||
quit(QuitSuccess)
|
||||
|
||||
proc writeVersion() =
|
||||
echo("nimble v$# compiled at $# $#" %
|
||||
[nimbleVersion, CompileDate, CompileTime])
|
||||
quit(QuitSuccess)
|
||||
|
||||
proc parseActionType*(action: string): ActionType =
|
||||
case action.normalize()
|
||||
of "install", "path":
|
||||
|
|
@ -153,7 +158,7 @@ proc initAction*(options: var Options, key: string) =
|
|||
options.action.arguments = @[]
|
||||
options.action.flags = newStringTable()
|
||||
of actionBuild, actionPublish, actionList, actionTasks,
|
||||
actionNil, actionVersion: discard
|
||||
actionNil: discard
|
||||
|
||||
proc prompt*(options: Options, question: string): bool =
|
||||
## Asks an interactive question and returns the result.
|
||||
|
|
@ -191,7 +196,13 @@ proc renameBabelToNimble(options: Options) {.deprecated.} =
|
|||
removeFile(nimbleDir / "babeldata.json")
|
||||
|
||||
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 =
|
||||
options.getNimbleDir() / "pkgs"
|
||||
|
|
@ -247,13 +258,11 @@ proc parseFlag*(flag, val: string, result: var Options) =
|
|||
# TODO: These should not be global.
|
||||
case flag.normalize()
|
||||
of "help", "h": writeHelp()
|
||||
of "version", "v":
|
||||
assert result.action.typ == actionNil
|
||||
result.action.typ = actionVersion
|
||||
of "version", "v": writeVersion()
|
||||
of "accept", "y": result.forcePrompts = forcePromptYes
|
||||
of "reject", "n": result.forcePrompts = forcePromptNo
|
||||
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 "depsonly", "d": result.depsOnly = true
|
||||
else:
|
||||
|
|
@ -262,6 +271,7 @@ proc parseFlag*(flag, val: string, result: var Options) =
|
|||
proc initOptions*(): Options =
|
||||
result.action.typ = actionNil
|
||||
result.pkgInfoCache = newTable[string, PackageInfo]()
|
||||
result.nimbleDir = ""
|
||||
|
||||
proc parseMisc(options: var Options) =
|
||||
# Load nimbledata.json
|
||||
|
|
@ -278,9 +288,9 @@ proc parseMisc(options: var Options) =
|
|||
|
||||
proc parseCmdLine*(): Options =
|
||||
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():
|
||||
case kind
|
||||
of cmdArgument:
|
||||
|
|
@ -292,6 +302,9 @@ proc parseCmdLine*(): Options =
|
|||
parseFlag(key, val, result)
|
||||
of cmdEnd: assert(false) # cannot happen
|
||||
|
||||
# Parse config.
|
||||
result.config = parseConfig()
|
||||
|
||||
# Parse other things, for example the nimbledata.json file.
|
||||
parseMisc(result)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue