Rename 'opt' back to 'options'.

This commit is contained in:
Dominik Picheta 2015-11-07 16:15:47 +00:00
commit 26f5fcdd3f

View file

@ -10,7 +10,7 @@ import nimblepkg/packageinfo, nimblepkg/version, nimblepkg/tools,
nimblepkg/download, nimblepkg/config, nimblepkg/nimbletypes, nimblepkg/download, nimblepkg/config, nimblepkg/nimbletypes,
nimblepkg/publish nimblepkg/publish
import compiler/options import compiler/options as compiler_options
when not defined(windows): when not defined(windows):
from posix import getpid from posix import getpid
@ -117,21 +117,21 @@ proc writeVersion() =
[nimbleVersion, CompileDate, CompileTime]) [nimbleVersion, CompileDate, CompileTime])
quit(QuitSuccess) quit(QuitSuccess)
proc getNimbleDir(opt: Options): string = proc getNimbleDir(options: Options): string =
opt.config.nimbleDir options.config.nimbleDir
proc getPkgsDir(opt: Options): string = proc getPkgsDir(options: Options): string =
opt.config.nimbleDir / "pkgs" options.config.nimbleDir / "pkgs"
proc getBinDir(opt: Options): string = proc getBinDir(options: Options): string =
opt.config.nimbleDir / "bin" options.config.nimbleDir / "bin"
proc prompt(opt: 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.
## ##
## The proc will return immediately without asking the user if the global ## The proc will return immediately without asking the user if the global
## forcePrompts has a value different than dontForcePrompt. ## forcePrompts has a value different than dontForcePrompt.
case opt.forcePrompts case options.forcePrompts
of forcePromptYes: of forcePromptYes:
echo(question & " -> [forced yes]") echo(question & " -> [forced yes]")
return true return true
@ -149,11 +149,11 @@ proc prompt(opt: Options, question: string): bool =
else: else:
return false return false
proc renameBabelToNimble(opt: Options) {.deprecated.} = proc renameBabelToNimble(options: Options) {.deprecated.} =
let babelDir = getHomeDir() / ".babel" let babelDir = getHomeDir() / ".babel"
let nimbleDir = getHomeDir() / ".nimble" let nimbleDir = getHomeDir() / ".nimble"
if dirExists(babelDir): if dirExists(babelDir):
if opt.prompt("Found deprecated babel package directory, would you " & if options.prompt("Found deprecated babel package directory, would you " &
"like to rename it to nimble?"): "like to rename it to nimble?"):
copyDir(babelDir, nimbleDir) copyDir(babelDir, nimbleDir)
copyFile(babelDir / "babeldata.json", nimbleDir / "nimbledata.json") copyFile(babelDir / "babeldata.json", nimbleDir / "nimbledata.json")
@ -168,7 +168,7 @@ proc parseCmdLine(): Options =
case kind case kind
of cmdArgument: of cmdArgument:
if result.action.typ == actionNil: if result.action.typ == actionNil:
options.command = key compiler_options.command = key
case key.normalize() case key.normalize()
of "install", "path": of "install", "path":
case key.normalize() case key.normalize()
@ -274,18 +274,18 @@ proc parseCmdLine(): Options =
else: else:
result.nimbleData = %{"reverseDeps": newJObject()} result.nimbleData = %{"reverseDeps": newJObject()}
proc update(opt: Options) = proc update(options: Options) =
## Downloads the package list from the specified URL. ## Downloads the package list from the specified URL.
## ##
## If the download is successful, the global didUpdatePackages is set to ## If the download is successful, the global didUpdatePackages is set to
## true. Otherwise an exception is raised on error. ## true. Otherwise an exception is raised on error.
let url = let url =
if opt.action.typ == actionUpdate and opt.action.optionalURL != "": if options.action.typ == actionUpdate and options.action.optionalURL != "":
opt.action.optionalURL options.action.optionalURL
else: else:
defaultPackageURL defaultPackageURL
echo("Downloading package list from " & url) echo("Downloading package list from " & url)
downloadFile(url, opt.getNimbleDir() / "packages.json") downloadFile(url, options.getNimbleDir() / "packages.json")
echo("Done.") echo("Done.")
proc checkInstallFile(pkgInfo: PackageInfo, proc checkInstallFile(pkgInfo: PackageInfo,
@ -336,7 +336,7 @@ proc copyWithExt(origDir, currentDir, dest: string,
result.add copyFileD(path, changeRoot(origDir, dest, path)) result.add copyFileD(path, changeRoot(origDir, dest, path))
proc copyFilesRec(origDir, currentDir, dest: string, proc copyFilesRec(origDir, currentDir, dest: string,
opt: Options, pkgInfo: PackageInfo): HashSet[string] = options: Options, pkgInfo: PackageInfo): HashSet[string] =
## Copies all the required files, skips files specified in the .nimble file ## Copies all the required files, skips files specified in the .nimble file
## (PackageInfo). ## (PackageInfo).
## Returns a list of filepaths to files which have been installed. ## Returns a list of filepaths to files which have been installed.
@ -349,7 +349,7 @@ proc copyFilesRec(origDir, currentDir, dest: string,
for file in pkgInfo.installFiles: for file in pkgInfo.installFiles:
let src = origDir / file let src = origDir / file
if not src.existsFile(): if not src.existsFile():
if opt.prompt("Missing file " & src & ". Continue?"): if options.prompt("Missing file " & src & ". Continue?"):
continue continue
else: else:
quit(QuitSuccess) quit(QuitSuccess)
@ -360,7 +360,7 @@ proc copyFilesRec(origDir, currentDir, dest: string,
# TODO: Allow skipping files inside dirs? # TODO: Allow skipping files inside dirs?
let src = origDir / dir let src = origDir / dir
if not src.existsDir(): if not src.existsDir():
if opt.prompt("Missing directory " & src & ". Continue?"): if options.prompt("Missing directory " & src & ". Continue?"):
continue continue
else: else:
quit(QuitSuccess) quit(QuitSuccess)
@ -376,7 +376,7 @@ proc copyFilesRec(origDir, currentDir, dest: string,
# Create the dir. # Create the dir.
createDir(changeRoot(origDir, dest, file)) createDir(changeRoot(origDir, dest, file))
result.incl copyFilesRec(origDir, file, dest, opt, pkgInfo) result.incl copyFilesRec(origDir, file, dest, options, pkgInfo)
else: else:
let skip = pkgInfo.checkInstallFile(origDir, file) let skip = pkgInfo.checkInstallFile(origDir, file)
@ -387,26 +387,26 @@ proc copyFilesRec(origDir, currentDir, dest: string,
result.incl copyFileD(pkgInfo.mypath, result.incl copyFileD(pkgInfo.mypath,
changeRoot(pkgInfo.mypath.splitFile.dir, dest, pkgInfo.mypath)) changeRoot(pkgInfo.mypath.splitFile.dir, dest, pkgInfo.mypath))
proc saveNimbleData(opt: Options) = proc saveNimbleData(options: Options) =
# TODO: This file should probably be locked. # TODO: This file should probably be locked.
writeFile(opt.getNimbleDir() / "nimbledata.json", writeFile(options.getNimbleDir() / "nimbledata.json",
pretty(opt.nimbleData)) pretty(options.nimbleData))
proc addRevDep(opt: Options, dep: tuple[name, version: string], proc addRevDep(options: Options, dep: tuple[name, version: string],
pkg: PackageInfo) = pkg: PackageInfo) =
# let depNameVer = dep.name & '-' & dep.version # let depNameVer = dep.name & '-' & dep.version
if not opt.nimbleData["reverseDeps"].hasKey(dep.name): if not options.nimbleData["reverseDeps"].hasKey(dep.name):
opt.nimbleData["reverseDeps"][dep.name] = newJObject() options.nimbleData["reverseDeps"][dep.name] = newJObject()
if not opt.nimbleData["reverseDeps"][dep.name].hasKey(dep.version): if not options.nimbleData["reverseDeps"][dep.name].hasKey(dep.version):
opt.nimbleData["reverseDeps"][dep.name][dep.version] = newJArray() options.nimbleData["reverseDeps"][dep.name][dep.version] = newJArray()
let revDep = %{ "name": %pkg.name, "version": %pkg.version} let revDep = %{ "name": %pkg.name, "version": %pkg.version}
let thisDep = opt.nimbleData["reverseDeps"][dep.name][dep.version] let thisDep = options.nimbleData["reverseDeps"][dep.name][dep.version]
if revDep notin thisDep: if revDep notin thisDep:
thisDep.add revDep thisDep.add revDep
proc removeRevDep(opt: Options, pkg: PackageInfo) = proc removeRevDep(options: Options, pkg: PackageInfo) =
## Removes ``pkg`` from the reverse dependencies of every package. ## Removes ``pkg`` from the reverse dependencies of every package.
proc remove(opt: Options, pkg: PackageInfo, depTup: PkgTuple, proc remove(options: Options, pkg: PackageInfo, depTup: PkgTuple,
thisDep: JsonNode) = thisDep: JsonNode) =
for ver, val in thisDep: for ver, val in thisDep:
if ver.newVersion in depTup.ver: if ver.newVersion in depTup.ver:
@ -420,16 +420,16 @@ proc removeRevDep(opt: Options, pkg: PackageInfo) =
for depTup in pkg.requires: for depTup in pkg.requires:
if depTup.name.isURL(): if depTup.name.isURL():
# We sadly must go through everything in this case... # We sadly must go through everything in this case...
for key, val in opt.nimbleData["reverseDeps"]: for key, val in options.nimbleData["reverseDeps"]:
opt.remove(pkg, depTup, val) options.remove(pkg, depTup, val)
else: else:
let thisDep = opt.nimbleData["reverseDeps"][depTup.name] let thisDep = options.nimbleData["reverseDeps"][depTup.name]
if thisDep.isNil: continue if thisDep.isNil: continue
opt.remove(pkg, depTup, thisDep) options.remove(pkg, depTup, thisDep)
# Clean up empty objects/arrays # Clean up empty objects/arrays
var newData = newJObject() var newData = newJObject()
for key, val in opt.nimbleData["reverseDeps"]: for key, val in options.nimbleData["reverseDeps"]:
if val.len != 0: if val.len != 0:
var newVal = newJObject() var newVal = newJObject()
for ver, elem in val: for ver, elem in val:
@ -437,19 +437,19 @@ proc removeRevDep(opt: Options, pkg: PackageInfo) =
newVal[ver] = elem newVal[ver] = elem
if newVal.len != 0: if newVal.len != 0:
newData[key] = newVal newData[key] = newVal
opt.nimbleData["reverseDeps"] = newData options.nimbleData["reverseDeps"] = newData
saveNimbleData(opt) saveNimbleData(options)
proc install(packages: seq[PkgTuple], proc install(packages: seq[PkgTuple],
opt: Options, options: Options,
doPrompt = true): tuple[paths: seq[string], pkg: PackageInfo] doPrompt = true): tuple[paths: seq[string], pkg: PackageInfo]
proc processDeps(pkginfo: PackageInfo, opt: Options): seq[string] = proc processDeps(pkginfo: PackageInfo, options: Options): seq[string] =
## Verifies and installs dependencies. ## Verifies and installs dependencies.
## ##
## Returns the list of paths to pass to the compiler during build phase. ## Returns the list of paths to pass to the compiler during build phase.
result = @[] result = @[]
let pkglist = getInstalledPkgs(opt.getPkgsDir()) let pkglist = getInstalledPkgs(options.getPkgsDir())
var reverseDeps: seq[tuple[name, version: string]] = @[] var reverseDeps: seq[tuple[name, version: string]] = @[]
for dep in pkginfo.requires: for dep in pkginfo.requires:
if dep.name == "nimrod" or dep.name == "nim": if dep.name == "nimrod" or dep.name == "nim":
@ -461,7 +461,7 @@ proc processDeps(pkginfo: PackageInfo, opt: Options): seq[string] =
var pkg: PackageInfo var pkg: PackageInfo
if not findPkg(pkglist, dep, pkg): if not findPkg(pkglist, dep, pkg):
echo("None found, installing...") echo("None found, installing...")
let (paths, installedPkg) = install(@[(dep.name, dep.ver)], opt) let (paths, installedPkg) = install(@[(dep.name, dep.ver)], options)
result.add(paths) result.add(paths)
pkg = installedPkg # For addRevDep pkg = installedPkg # For addRevDep
@ -469,7 +469,7 @@ proc processDeps(pkginfo: PackageInfo, opt: Options): seq[string] =
echo("Dependency already satisfied.") echo("Dependency already satisfied.")
result.add(pkg.mypath.splitFile.dir) result.add(pkg.mypath.splitFile.dir)
# Process the dependencies of this dependency. # Process the dependencies of this dependency.
result.add(processDeps(pkg, opt)) result.add(processDeps(pkg, options))
reverseDeps.add((pkg.name, pkg.version)) reverseDeps.add((pkg.name, pkg.version))
# Check if two packages of the same name (but different version) are listed # Check if two packages of the same name (but different version) are listed
@ -487,8 +487,8 @@ proc processDeps(pkginfo: PackageInfo, opt: Options): seq[string] =
# them added if the above errorenous condition occurs # them added if the above errorenous condition occurs
# (unsatisfiable dependendencies). # (unsatisfiable dependendencies).
for i in reverseDeps: for i in reverseDeps:
addRevDep(opt, i, pkginfo) addRevDep(options, i, pkginfo)
saveNimbleData(opt) saveNimbleData(options)
proc buildFromDir(pkgInfo: PackageInfo, paths: seq[string], forRelease: bool) = proc buildFromDir(pkgInfo: PackageInfo, paths: seq[string], forRelease: bool) =
## Builds a package as specified by ``pkgInfo``. ## Builds a package as specified by ``pkgInfo``.
@ -515,7 +515,7 @@ proc saveNimbleMeta(pkgDestDir, url: string, filesInstalled: HashSet[string]) =
nimblemeta["files"].add(%changeRoot(pkgDestDir, "", file)) nimblemeta["files"].add(%changeRoot(pkgDestDir, "", file))
writeFile(pkgDestDir / "nimblemeta.json", $nimblemeta) writeFile(pkgDestDir / "nimblemeta.json", $nimblemeta)
proc removePkgDir(dir: string, opt: Options) = proc removePkgDir(dir: string, options: Options) =
## Removes files belonging to the package in ``dir``. ## Removes files belonging to the package in ``dir``.
try: try:
var nimblemeta = parseFile(dir / "nimblemeta.json") var nimblemeta = parseFile(dir / "nimblemeta.json")
@ -535,12 +535,12 @@ proc removePkgDir(dir: string, opt: Options) =
". Files not installed by nimble are present.") ". Files not installed by nimble are present.")
except OSError, JsonParsingError: except OSError, JsonParsingError:
echo("Error: Unable to read nimblemeta.json: ", getCurrentExceptionMsg()) echo("Error: Unable to read nimblemeta.json: ", getCurrentExceptionMsg())
if not opt.prompt("Would you like to COMPLETELY remove ALL files " & if not options.prompt("Would you like to COMPLETELY remove ALL files " &
"in " & dir & "?"): "in " & dir & "?"):
quit(QuitSuccess) quit(QuitSuccess)
removeDir(dir) removeDir(dir)
proc installFromDir(dir: string, latest: bool, opt: Options, proc installFromDir(dir: string, latest: bool, options: Options,
url: string): tuple[paths: seq[string], pkg: PackageInfo] = url: string): tuple[paths: seq[string], pkg: PackageInfo] =
## Returns where package has been installed to, together with paths ## Returns where package has been installed to, together with paths
## to the packages this package depends on. ## to the packages this package depends on.
@ -548,10 +548,10 @@ proc installFromDir(dir: string, latest: bool, opt: Options,
## ``processDeps`` to gather a list of paths to pass to the nim compiler. ## ``processDeps`` to gather a list of paths to pass to the nim compiler.
var pkgInfo = getPkgInfo(dir) var pkgInfo = getPkgInfo(dir)
let realDir = pkgInfo.getRealDir() let realDir = pkgInfo.getRealDir()
let binDir = opt.getBinDir() let binDir = options.getBinDir()
let pkgsDir = opt.getPkgsDir() let pkgsDir = options.getPkgsDir()
# Dependencies need to be processed before the creation of the pkg dir. # Dependencies need to be processed before the creation of the pkg dir.
result.paths = processDeps(pkginfo, opt) result.paths = processDeps(pkginfo, options)
echo("Installing ", pkginfo.name, "-", pkginfo.version) echo("Installing ", pkginfo.name, "-", pkginfo.version)
@ -562,10 +562,10 @@ proc installFromDir(dir: string, latest: bool, opt: Options,
let versionStr = (if latest: "" else: '-' & pkgInfo.version) let versionStr = (if latest: "" else: '-' & pkgInfo.version)
let pkgDestDir = pkgsDir / (pkgInfo.name & versionStr) let pkgDestDir = pkgsDir / (pkgInfo.name & versionStr)
if existsDir(pkgDestDir) and existsFile(pkgDestDir / "nimblemeta.json"): if existsDir(pkgDestDir) and existsFile(pkgDestDir / "nimblemeta.json"):
if not opt.prompt(pkgInfo.name & versionStr & if not options.prompt(pkgInfo.name & versionStr &
" already exists. Overwrite?"): " already exists. Overwrite?"):
quit(QuitSuccess) quit(QuitSuccess)
removePkgDir(pkgDestDir, opt) removePkgDir(pkgDestDir, options)
# Remove any symlinked binaries # Remove any symlinked binaries
for bin in pkgInfo.bin: for bin in pkgInfo.bin:
# TODO: Check that this binary belongs to the package being installed. # TODO: Check that this binary belongs to the package being installed.
@ -585,7 +585,7 @@ proc installFromDir(dir: string, latest: bool, opt: Options,
if pkgInfo.bin.len > 0: if pkgInfo.bin.len > 0:
createDir(binDir) createDir(binDir)
# Copy all binaries and files that are not skipped # Copy all binaries and files that are not skipped
filesInstalled = copyFilesRec(realDir, realDir, pkgDestDir, opt, filesInstalled = copyFilesRec(realDir, realDir, pkgDestDir, options,
pkgInfo) pkgInfo)
# Set file permissions to +x for all binaries built, # Set file permissions to +x for all binaries built,
# and symlink them on *nix OS' to $nimbleDir/bin/ # and symlink them on *nix OS' to $nimbleDir/bin/
@ -617,7 +617,7 @@ proc installFromDir(dir: string, latest: bool, opt: Options,
let dest = binDir / cleanBin.changeFileExt("cmd") let dest = binDir / cleanBin.changeFileExt("cmd")
echo("Creating stub: ", pkgDestDir / bin, " -> ", dest) echo("Creating stub: ", pkgDestDir / bin, " -> ", dest)
var contents = "@" var contents = "@"
if opt.config.chcp: if options.config.chcp:
if fixChcp: if fixChcp:
contents.add "chcp 65001 > nul && " contents.add "chcp 65001 > nul && "
else: contents.add "chcp 65001 > nul\n@" else: contents.add "chcp 65001 > nul\n@"
@ -630,7 +630,7 @@ proc installFromDir(dir: string, latest: bool, opt: Options,
else: else:
{.error: "Sorry, your platform is not supported.".} {.error: "Sorry, your platform is not supported.".}
else: else:
filesInstalled = copyFilesRec(realDir, realDir, pkgDestDir, opt, filesInstalled = copyFilesRec(realDir, realDir, pkgDestDir, options,
pkgInfo) pkgInfo)
# Save a nimblemeta.json file. # Save a nimblemeta.json file.
@ -669,46 +669,46 @@ proc downloadPkg(url: string, verRange: VersionRange,
echo("Downloading ", url, " into ", downloadDir, " using ", downMethod, "...") echo("Downloading ", url, " into ", downloadDir, " using ", downMethod, "...")
result = (downloadDir, doDownload(url, downloadDir, verRange, downMethod)) result = (downloadDir, doDownload(url, downloadDir, verRange, downMethod))
proc getDownloadInfo*(pv: PkgTuple, opt: Options, proc getDownloadInfo*(pv: PkgTuple, options: Options,
doPrompt: bool): (DownloadMethod, string) = doPrompt: bool): (DownloadMethod, string) =
if pv.name.isURL: if pv.name.isURL:
return (checkUrlType(pv.name), pv.name) return (checkUrlType(pv.name), pv.name)
else: else:
var pkg: Package var pkg: Package
if getPackage(pv.name, opt.getNimbleDir() / "packages.json", pkg): if getPackage(pv.name, options.getNimbleDir() / "packages.json", pkg):
return (pkg.downloadMethod.getDownloadMethod(), pkg.url) return (pkg.downloadMethod.getDownloadMethod(), pkg.url)
else: else:
# If package is not found give the user a chance to update # If package is not found give the user a chance to update
# package.json # package.json
if doPrompt and if doPrompt and
opt.prompt(pv.name & " not found in local packages.json, " & options.prompt(pv.name & " not found in local packages.json, " &
"check internet for updated packages?"): "check internet for updated packages?"):
update(opt) update(options)
return getDownloadInfo(pv, opt, doPrompt) return getDownloadInfo(pv, options, doPrompt)
else: else:
raise newException(NimbleError, "Package not found.") raise newException(NimbleError, "Package not found.")
proc install(packages: seq[PkgTuple], proc install(packages: seq[PkgTuple],
opt: Options, options: Options,
doPrompt = true): tuple[paths: seq[string], pkg: PackageInfo] = doPrompt = true): tuple[paths: seq[string], pkg: PackageInfo] =
if packages == @[]: if packages == @[]:
result = installFromDir(getCurrentDir(), false, opt, "") result = installFromDir(getCurrentDir(), false, options, "")
else: else:
# If packages.json is not present ask the user if they want to download it. # If packages.json is not present ask the user if they want to download it.
if not existsFile(opt.getNimbleDir / "packages.json"): if not existsFile(options.getNimbleDir / "packages.json"):
if doPrompt and if doPrompt and
opt.prompt("Local packages.json not found, download it from " & options.prompt("Local packages.json not found, download it from " &
"internet?"): "internet?"):
update(opt) update(options)
else: else:
quit("Please run nimble update.", QuitFailure) quit("Please run nimble update.", QuitFailure)
# Install each package. # Install each package.
for pv in packages: for pv in packages:
let (meth, url) = getDownloadInfo(pv, opt, doPrompt) let (meth, url) = getDownloadInfo(pv, options, doPrompt)
let (downloadDir, downloadVersion) = downloadPkg(url, pv.ver, meth) let (downloadDir, downloadVersion) = downloadPkg(url, pv.ver, meth)
try: try:
result = installFromDir(downloadDir, false, opt, url) result = installFromDir(downloadDir, false, options, url)
except BuildFailed: except BuildFailed:
# The package failed to build. # The package failed to build.
# Check if we tried building a tagged version of the package. # Check if we tried building a tagged version of the package.
@ -717,37 +717,37 @@ proc install(packages: seq[PkgTuple],
# If we tried building a tagged version of the package then # If we tried building a tagged version of the package then
# ask the user whether they want to try building #head. # ask the user whether they want to try building #head.
let promptResult = doPrompt and let promptResult = doPrompt and
opt.prompt(("Build failed for '$1@$2', would you" & options.prompt(("Build failed for '$1@$2', would you" &
" like to try installing '$1@#head' (latest unstable)?") % " like to try installing '$1@#head' (latest unstable)?") %
[pv.name, $downloadVersion]) [pv.name, $downloadVersion])
if promptResult: if promptResult:
result = install(@[(pv.name, headVer)], opt, doPrompt) result = install(@[(pv.name, headVer)], options, doPrompt)
else: else:
raise newException(BuildFailed, raise newException(BuildFailed,
"Aborting installation due to build failure") "Aborting installation due to build failure")
else: else:
raise raise
proc build(opt: Options) = proc build(options: Options) =
var pkgInfo = getPkgInfo(getCurrentDir()) var pkgInfo = getPkgInfo(getCurrentDir())
let paths = processDeps(pkginfo, opt) let paths = processDeps(pkginfo, options)
buildFromDir(pkgInfo, paths, false) buildFromDir(pkgInfo, paths, false)
proc compile(opt: Options) = proc compile(options: Options) =
var pkgInfo = getPkgInfo(getCurrentDir()) var pkgInfo = getPkgInfo(getCurrentDir())
let paths = processDeps(pkginfo, opt) let paths = processDeps(pkginfo, options)
let realDir = pkgInfo.getRealDir() let realDir = pkgInfo.getRealDir()
var args = "" var args = ""
for path in paths: args.add("--path:\"" & path & "\" ") for path in paths: args.add("--path:\"" & path & "\" ")
for option in opt.action.compileOptions: for option in options.action.compileOptions:
args.add(option & " ") args.add(option & " ")
let bin = opt.action.file let bin = options.action.file
let backend = let backend =
if opt.action.backend.len > 0: if options.action.backend.len > 0:
opt.action.backend options.action.backend
else: else:
pkgInfo.backend pkgInfo.backend
@ -759,27 +759,27 @@ proc compile(opt: Options) =
doCmd(getNimBin() & " $# --noBabelPath $# \"$#\"" % doCmd(getNimBin() & " $# --noBabelPath $# \"$#\"" %
[backend, args, bin]) [backend, args, bin])
proc search(opt: Options) = proc search(options: Options) =
## Searches for matches in ``opt.action.search``. ## Searches for matches in ``options.action.search``.
## ##
## Searches are done in a case insensitive way making all strings lower case. ## Searches are done in a case insensitive way making all strings lower case.
assert opt.action.typ == actionSearch assert options.action.typ == actionSearch
if opt.action.search == @[]: if options.action.search == @[]:
raise newException(NimbleError, "Please specify a search string.") raise newException(NimbleError, "Please specify a search string.")
if not existsFile(opt.getNimbleDir() / "packages.json"): if not existsFile(options.getNimbleDir() / "packages.json"):
raise newException(NimbleError, "Please run nimble update.") raise newException(NimbleError, "Please run nimble update.")
let pkgList = getPackageList(opt.getNimbleDir() / "packages.json") let pkgList = getPackageList(options.getNimbleDir() / "packages.json")
var found = false var found = false
template onFound: stmt = template onFound: stmt =
echoPackage(pkg) echoPackage(pkg)
if opt.queryVersions: if options.queryVersions:
echoPackageVersions(pkg) echoPackageVersions(pkg)
echo(" ") echo(" ")
found = true found = true
break break
for pkg in pkgList: for pkg in pkgList:
for word in opt.action.search: for word in options.action.search:
# Search by name. # Search by name.
if word.toLower() in pkg.name.toLower(): if word.toLower() in pkg.name.toLower():
onFound() onFound()
@ -791,19 +791,19 @@ proc search(opt: Options) =
if not found: if not found:
echo("No package found.") echo("No package found.")
proc list(opt: Options) = proc list(options: Options) =
if not existsFile(opt.getNimbleDir() / "packages.json"): if not existsFile(options.getNimbleDir() / "packages.json"):
raise newException(NimbleError, "Please run nimble update.") raise newException(NimbleError, "Please run nimble update.")
let pkgList = getPackageList(opt.getNimbleDir() / "packages.json") let pkgList = getPackageList(options.getNimbleDir() / "packages.json")
for pkg in pkgList: for pkg in pkgList:
echoPackage(pkg) echoPackage(pkg)
if opt.queryVersions: if options.queryVersions:
echoPackageVersions(pkg) echoPackageVersions(pkg)
echo(" ") echo(" ")
proc listInstalled(opt: Options) = proc listInstalled(options: Options) =
var h = initTable[string, seq[string]]() var h = initTable[string, seq[string]]()
let pkgs = getInstalledPkgs(opt.getPkgsDir()) let pkgs = getInstalledPkgs(options.getPkgsDir())
for x in pkgs.items(): for x in pkgs.items():
let let
pName = x.pkginfo.name pName = x.pkginfo.name
@ -817,7 +817,7 @@ proc listInstalled(opt: Options) =
type VersionAndPath = tuple[version: Version, path: string] type VersionAndPath = tuple[version: Version, path: string]
proc listPaths(opt: Options) = proc listPaths(options: Options) =
## Loops over installing packages displaying their installed paths. ## Loops over installing packages displaying their installed paths.
## ##
## If there are several packages installed, only the last one (the version ## If there are several packages installed, only the last one (the version
@ -826,14 +826,14 @@ proc listPaths(opt: Options) =
## but at the end quits with a non zero exit error. ## but at the end quits with a non zero exit error.
## ##
## On success the proc returns normally. ## On success the proc returns normally.
assert opt.action.typ == actionPath assert options.action.typ == actionPath
assert(not opt.action.packages.isNil) assert(not options.action.packages.isNil)
var errors = 0 var errors = 0
for name, version in opt.action.packages.items: for name, version in options.action.packages.items:
var installed: seq[VersionAndPath] = @[] var installed: seq[VersionAndPath] = @[]
# There may be several, list all available ones and sort by version. # There may be several, list all available ones and sort by version.
for kind, path in walkDir(opt.getPkgsDir): for kind, path in walkDir(options.getPkgsDir):
if kind != pcDir or not path.startsWith(opt.getPkgsDir / name): if kind != pcDir or not path.startsWith(options.getPkgsDir / name):
continue continue
let let
@ -846,7 +846,7 @@ proc listPaths(opt: Options) =
var pkgInfo = getPkgInfo(path) var pkgInfo = getPkgInfo(path)
var v: VersionAndPath var v: VersionAndPath
v.version = newVersion(pkgInfo.version) v.version = newVersion(pkgInfo.version)
v.path = opt.getPkgsDir / (pkgInfo.name & '-' & pkgInfo.version) v.path = options.getPkgsDir / (pkgInfo.name & '-' & pkgInfo.version)
installed.add(v) installed.add(v)
else: else:
echo "Warning: No .nimble file found for ", path echo "Warning: No .nimble file found for ", path
@ -874,8 +874,8 @@ proc join(x: seq[PkgTuple]; y: string): string =
result.add y result.add y
result.add x[i][0] & " " & $x[i][1] result.add x[i][0] & " " & $x[i][1]
proc dump(opt: Options) = proc dump(options: Options) =
let proj = addFileExt(opt.action.projName, NimsExt) let proj = addFileExt(options.action.projName, NimsExt)
let p = if fileExists(proj): readPackageInfo((true, proj)) let p = if fileExists(proj): readPackageInfo((true, proj))
else: getPkgInfo(os.getCurrentDir()) else: getPkgInfo(os.getCurrentDir())
echo "name: ", p.name.escape echo "name: ", p.name.escape
@ -895,14 +895,14 @@ proc dump(opt: Options) =
echo "srcDir: ", p.srcDir.escape echo "srcDir: ", p.srcDir.escape
echo "backend: ", p.backend.escape echo "backend: ", p.backend.escape
proc init(opt: Options) = proc init(options: Options) =
echo("Initializing new Nimble project!") echo("Initializing new Nimble project!")
var var
pkgName, fName: string = "" pkgName, fName: string = ""
outFile: File outFile: File
if opt.action.projName != "": if options.action.projName != "":
pkgName = opt.action.projName pkgName = options.action.projName
fName = pkgName & NimsExt fName = pkgName & NimsExt
if (existsFile(os.getCurrentDir() / fName)): if (existsFile(os.getCurrentDir() / fName)):
raise newException(NimbleError, "Already have a nimscript file.") raise newException(NimbleError, "Already have a nimscript file.")
@ -936,16 +936,16 @@ requires "nim >= "0.11.2"
raise newException(NimbleError, "Unable to open file " & fName & raise newException(NimbleError, "Unable to open file " & fName &
" for writing: " & osErrorMsg(osLastError())) " for writing: " & osErrorMsg(osLastError()))
proc uninstall(opt: Options) = proc uninstall(options: Options) =
if opt.action.packages.len == 0: if options.action.packages.len == 0:
raise newException(NimbleError, raise newException(NimbleError,
"Please specify the package(s) to uninstall.") "Please specify the package(s) to uninstall.")
var pkgsToDelete: seq[PackageInfo] = @[] var pkgsToDelete: seq[PackageInfo] = @[]
# Do some verification. # Do some verification.
for pkgTup in opt.action.packages: for pkgTup in options.action.packages:
echo("Looking for ", pkgTup.name, " (", $pkgTup.ver, ")...") echo("Looking for ", pkgTup.name, " (", $pkgTup.ver, ")...")
let installedPkgs = getInstalledPkgs(opt.getPkgsDir()) let installedPkgs = getInstalledPkgs(options.getPkgsDir())
var pkgList = findAllPkgs(installedPkgs, pkgTup) var pkgList = findAllPkgs(installedPkgs, pkgTup)
if pkgList.len == 0: if pkgList.len == 0:
raise newException(NimbleError, "Package not found") raise newException(NimbleError, "Package not found")
@ -955,7 +955,7 @@ proc uninstall(opt: Options) =
for pkg in pkgList: for pkg in pkgList:
# Check whether any packages depend on the ones the user is trying to # Check whether any packages depend on the ones the user is trying to
# uninstall. # uninstall.
let thisPkgsDep = opt.nimbleData["reverseDeps"]{pkg.name}{pkg.version} let thisPkgsDep = options.nimbleData["reverseDeps"]{pkg.name}{pkg.version}
if not thisPkgsDep.isNil: if not thisPkgsDep.isNil:
var reason = "" var reason = ""
if thisPkgsDep.len == 1: if thisPkgsDep.len == 1:
@ -983,49 +983,49 @@ proc uninstall(opt: Options) =
pkgNames.add pkg.name & " (" & pkg.version & ")" pkgNames.add pkg.name & " (" & pkg.version & ")"
# Let's confirm that the user wants these packages removed. # Let's confirm that the user wants these packages removed.
if not opt.prompt("The following packages will be removed:\n " & if not options.prompt("The following packages will be removed:\n " &
pkgNames & "\nDo you wish to continue?"): pkgNames & "\nDo you wish to continue?"):
quit(QuitSuccess) quit(QuitSuccess)
for pkg in pkgsToDelete: for pkg in pkgsToDelete:
# If we reach this point then the package can be safely removed. # If we reach this point then the package can be safely removed.
removeRevDep(opt, pkg) removeRevDep(options, pkg)
removePkgDir(opt.getPkgsDir / (pkg.name & '-' & pkg.version), opt) removePkgDir(options.getPkgsDir / (pkg.name & '-' & pkg.version), options)
echo("Removed ", pkg.name, " (", $pkg.version, ")") echo("Removed ", pkg.name, " (", $pkg.version, ")")
proc getCommand: string = options.command proc getCommand: string = compiler_options.command
proc doAction(opt: Options) = proc doAction(options: Options) =
if not existsDir(opt.getNimbleDir()): if not existsDir(options.getNimbleDir()):
createDir(opt.getNimbleDir()) createDir(options.getNimbleDir())
if not existsDir(opt.getPkgsDir): if not existsDir(options.getPkgsDir):
createDir(opt.getPkgsDir) createDir(options.getPkgsDir)
case getCommand().normalize case getCommand().normalize
of "udpate": of "udpate":
update(opt) update(options)
of "install": of "install":
discard install(opt.action.packages, opt) discard install(options.action.packages, options)
of "uninstall", "remove", "delete", "del", "rm": of "uninstall", "remove", "delete", "del", "rm":
uninstall(opt) uninstall(options)
of "search": of "search":
search(opt) search(options)
of "list": of "list":
if opt.queryInstalled: listInstalled(opt) if options.queryInstalled: listInstalled(options)
else: list(opt) else: list(options)
of "path": of "path":
listPaths(opt) listPaths(options)
of "build": of "build":
build(opt) build(options)
of "c", "compile", "js", "cpp", "cc": of "c", "compile", "js", "cpp", "cc":
compile(opt) compile(options)
of "init": of "init":
init(opt) init(options)
of "publish": of "publish":
var pkgInfo = getPkgInfo(getCurrentDir()) var pkgInfo = getPkgInfo(getCurrentDir())
publish(pkgInfo) publish(pkgInfo)
of "dump": of "dump":
dump(opt) dump(options)
of "nop": discard of "nop": discard
else: else:
raise newException(NimbleError, "Unknown command: " & getCommand()) raise newException(NimbleError, "Unknown command: " & getCommand())