Merge pull request #296 from nigredo-tori/better-dump
Change the way `dump` locates the project file
This commit is contained in:
commit
0c70b67a0a
4 changed files with 59 additions and 2 deletions
|
|
@ -807,8 +807,30 @@ 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 getPackageByPattern(pattern: string, options: Options): PackageInfo =
|
||||||
|
## Search for a package file using multiple strategies.
|
||||||
|
if pattern == "":
|
||||||
|
# Not specified - using current directory
|
||||||
|
result = getPkgInfo(os.getCurrentDir(), options)
|
||||||
|
elif pattern.splitFile.ext == ".nimble" and pattern.existsFile:
|
||||||
|
# project file specified
|
||||||
|
result = getPkgInfoFromFile(pattern, options)
|
||||||
|
elif pattern.existsDir:
|
||||||
|
# project directory specified
|
||||||
|
result = getPkgInfo(pattern, options)
|
||||||
|
else:
|
||||||
|
# Last resort - attempt to read as package identifier
|
||||||
|
let packages = getInstalledPkgsMin(options.getPkgsDir(), options)
|
||||||
|
let identTuple = parseRequires(pattern)
|
||||||
|
var skeletonInfo: PackageInfo
|
||||||
|
if not findPkg(packages, identTuple, skeletonInfo):
|
||||||
|
raise newException(NimbleError,
|
||||||
|
"Specified package not found"
|
||||||
|
)
|
||||||
|
result = getPkgInfoFromFile(skeletonInfo.myPath, options)
|
||||||
|
|
||||||
proc dump(options: Options) =
|
proc dump(options: Options) =
|
||||||
let p = getPkgInfo(os.getCurrentDir(), options)
|
let p = getPackageByPattern(options.action.projName, options)
|
||||||
echo "name: ", p.name.escape
|
echo "name: ", p.name.escape
|
||||||
echo "version: ", p.version.escape
|
echo "version: ", p.version.escape
|
||||||
echo "author: ", p.author.escape
|
echo "author: ", p.author.escape
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,10 @@ Commands:
|
||||||
path pkgname ... Shows absolute path to the installed packages
|
path pkgname ... Shows absolute path to the installed packages
|
||||||
specified.
|
specified.
|
||||||
dump [pkgname] Outputs Nimble package information for
|
dump [pkgname] Outputs Nimble package information for
|
||||||
external tools.
|
external tools. The argument can be a
|
||||||
|
.nimble file, a project directory or
|
||||||
|
the name of an installed package.
|
||||||
|
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
-h, --help Print this help message.
|
-h, --help Print this help message.
|
||||||
|
|
|
||||||
4
tests/testdump/testdump.nimble
Normal file
4
tests/testdump/testdump.nimble
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
description = "Test package for dump command"
|
||||||
|
version = "0.1.0"
|
||||||
|
author = "nigredo-tori"
|
||||||
|
license = "BSD"
|
||||||
|
|
@ -299,3 +299,31 @@ test "can uninstall":
|
||||||
check(not dirExists(installDir / "pkgs" / "PackageA-0.2.0"))
|
check(not dirExists(installDir / "pkgs" / "PackageA-0.2.0"))
|
||||||
|
|
||||||
check execNimble("uninstall", "-y", "nimscript").exitCode == QuitSuccess
|
check execNimble("uninstall", "-y", "nimscript").exitCode == QuitSuccess
|
||||||
|
|
||||||
|
test "can dump for current project":
|
||||||
|
cd "testdump":
|
||||||
|
let (outp, exitCode) = execNimble("dump")
|
||||||
|
check: exitCode == 0
|
||||||
|
check: outp.processOutput.inLines("desc: \"Test package for dump command\"")
|
||||||
|
|
||||||
|
test "can dump for project directory":
|
||||||
|
let (outp, exitCode) = execNimble("dump", "testdump")
|
||||||
|
check: exitCode == 0
|
||||||
|
check: outp.processOutput.inLines("desc: \"Test package for dump command\"")
|
||||||
|
|
||||||
|
test "can dump for project file":
|
||||||
|
let (outp, exitCode) = execNimble("dump", "testdump" / "testdump.nimble")
|
||||||
|
check: exitCode == 0
|
||||||
|
check: outp.processOutput.inLines("desc: \"Test package for dump command\"")
|
||||||
|
|
||||||
|
test "can dump for installed package":
|
||||||
|
cd "testdump":
|
||||||
|
check: execNimble("install", "-y").exitCode == 0
|
||||||
|
defer:
|
||||||
|
discard execNimble("remove", "-y", "testdump")
|
||||||
|
|
||||||
|
# Otherwise we might find subdirectory instead
|
||||||
|
cd "..":
|
||||||
|
let (outp, exitCode) = execNimble("dump", "testdump")
|
||||||
|
check: exitCode == 0
|
||||||
|
check: outp.processOutput.inLines("desc: \"Test package for dump command\"")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue