Normalise cmd line pkg name and ver range parsing.
This commit is contained in:
parent
509eff97a3
commit
a541387dfb
1 changed files with 6 additions and 17 deletions
|
|
@ -97,7 +97,6 @@ proc parseCmdLine(): TOptions =
|
||||||
result.action.typ = ActionInstall
|
result.action.typ = ActionInstall
|
||||||
of "path":
|
of "path":
|
||||||
result.action.typ = ActionPath
|
result.action.typ = ActionPath
|
||||||
result.action.optionalName = @[]
|
|
||||||
result.action.packages = @[]
|
result.action.packages = @[]
|
||||||
of "build":
|
of "build":
|
||||||
result.action.typ = ActionBuild
|
result.action.typ = ActionBuild
|
||||||
|
|
@ -112,15 +111,12 @@ proc parseCmdLine(): TOptions =
|
||||||
of "uninstall", "remove", "delete", "del", "rm":
|
of "uninstall", "remove", "delete", "del", "rm":
|
||||||
result.action.typ = ActionUninstall
|
result.action.typ = ActionUninstall
|
||||||
result.action.packages = @[]
|
result.action.packages = @[]
|
||||||
result.action.optionalName = @[]
|
|
||||||
else: writeHelp()
|
else: writeHelp()
|
||||||
else:
|
else:
|
||||||
case result.action.typ
|
case result.action.typ
|
||||||
of ActionNil:
|
of ActionNil:
|
||||||
assert false
|
assert false
|
||||||
of ActionInstall, ActionPath, ActionUninstall:
|
of ActionInstall, ActionPath, ActionUninstall:
|
||||||
result.action.optionalName.add(key)
|
|
||||||
|
|
||||||
# Parse pkg@verRange
|
# Parse pkg@verRange
|
||||||
if '@' in key:
|
if '@' in key:
|
||||||
let i = find(key, '@')
|
let i = find(key, '@')
|
||||||
|
|
@ -289,6 +285,7 @@ proc copyFilesRec(origDir, currentDir, dest: string,
|
||||||
changeRoot(pkgInfo.mypath.splitFile.dir, dest, pkgInfo.mypath))
|
changeRoot(pkgInfo.mypath.splitFile.dir, dest, pkgInfo.mypath))
|
||||||
|
|
||||||
proc saveBabelData(options: TOptions) =
|
proc saveBabelData(options: TOptions) =
|
||||||
|
# TODO: This file should probably be locked.
|
||||||
writeFile(options.getBabelDir() / "babeldata.json", pretty(options.babelData))
|
writeFile(options.getBabelDir() / "babeldata.json", pretty(options.babelData))
|
||||||
|
|
||||||
proc addRevDep(options: TOptions, dep: tuple[name, version: string],
|
proc addRevDep(options: TOptions, dep: tuple[name, version: string],
|
||||||
|
|
@ -340,7 +337,7 @@ proc removeRevDep(options: TOptions, pkg: TPackageInfo) =
|
||||||
|
|
||||||
saveBabelData(options)
|
saveBabelData(options)
|
||||||
|
|
||||||
proc install(packages: seq[tuple[name: string, verRange: PVersionRange]],
|
proc install(packages: seq[TPkgTuple],
|
||||||
options: TOptions,
|
options: TOptions,
|
||||||
doPrompt = true): tuple[paths: seq[string], pkg: TPackageInfo]
|
doPrompt = true): tuple[paths: seq[string], pkg: TPackageInfo]
|
||||||
proc processDeps(pkginfo: TPackageInfo, options: TOptions): seq[string] =
|
proc processDeps(pkginfo: TPackageInfo, options: TOptions): seq[string] =
|
||||||
|
|
@ -537,7 +534,7 @@ proc downloadPkg(pkg: TPackage, verRange: PVersionRange): string =
|
||||||
doDownload(pkg.url, downloadDir, verRange, downMethod)
|
doDownload(pkg.url, downloadDir, verRange, downMethod)
|
||||||
result = downloadDir
|
result = downloadDir
|
||||||
|
|
||||||
proc install(packages: seq[tuple[name: string, verRange: PVersionRange]],
|
proc install(packages: seq[TPkgTuple],
|
||||||
options: TOptions,
|
options: TOptions,
|
||||||
doPrompt = true): tuple[paths: seq[string], pkg: TPackageInfo] =
|
doPrompt = true): tuple[paths: seq[string], pkg: TPackageInfo] =
|
||||||
if packages == @[]:
|
if packages == @[]:
|
||||||
|
|
@ -555,12 +552,12 @@ proc install(packages: seq[tuple[name: string, verRange: PVersionRange]],
|
||||||
for pv in packages:
|
for pv in packages:
|
||||||
if pv.name.isURL:
|
if pv.name.isURL:
|
||||||
let meth = checkUrlType(pv.name)
|
let meth = checkUrlType(pv.name)
|
||||||
let downloadDir = downloadPkg(pv.name, pv.verRange, meth)
|
let downloadDir = downloadPkg(pv.name, pv.ver, meth)
|
||||||
result = installFromDir(downloadDir, false, options, pv.name)
|
result = installFromDir(downloadDir, false, options, pv.name)
|
||||||
else:
|
else:
|
||||||
var pkg: TPackage
|
var pkg: TPackage
|
||||||
if getPackage(pv.name, options.getBabelDir() / "packages.json", pkg):
|
if getPackage(pv.name, options.getBabelDir() / "packages.json", pkg):
|
||||||
let downloadDir = downloadPkg(pkg, pv.verRange)
|
let downloadDir = downloadPkg(pkg, pv.ver)
|
||||||
result = installFromDir(downloadDir, false, options, pkg.url)
|
result = installFromDir(downloadDir, false, options, pkg.url)
|
||||||
else:
|
else:
|
||||||
# If package is not found give the user a chance to update package.json
|
# If package is not found give the user a chance to update package.json
|
||||||
|
|
@ -720,15 +717,7 @@ proc doAction(options: TOptions) =
|
||||||
of ActionUpdate:
|
of ActionUpdate:
|
||||||
update(options)
|
update(options)
|
||||||
of ActionInstall:
|
of ActionInstall:
|
||||||
var installList: seq[tuple[name: string, verRange: PVersionRange]] = @[]
|
discard install(options.action.packages, options)
|
||||||
for name in options.action.optionalName:
|
|
||||||
if '#' in name: # TODO: Change this to allow babel install pkg@>0.1
|
|
||||||
let i = find(name, '#')
|
|
||||||
installList.add((name[0 .. i-1], name[i .. -1].parseVersionRange()))
|
|
||||||
else:
|
|
||||||
installList.add((name, PVersionRange(kind: verAny)))
|
|
||||||
|
|
||||||
discard install(installList, options)
|
|
||||||
of ActionUninstall:
|
of ActionUninstall:
|
||||||
uninstall(options)
|
uninstall(options)
|
||||||
of ActionSearch:
|
of ActionSearch:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue