implemented 'nimble dump' command

This commit is contained in:
Araq 2015-09-03 12:22:22 +02:00
commit 99332ce552

View file

@ -40,7 +40,7 @@ type
nimbleData: JsonNode ## Nimbledata.json nimbleData: JsonNode ## Nimbledata.json
ActionType = enum ActionType = enum
actionNil, actionUpdate, actionInit, actionPublish, actionNil, actionUpdate, actionInit, actionDump, actionPublish,
actionInstall, actionSearch, actionInstall, actionSearch,
actionList, actionBuild, actionPath, actionUninstall, actionCompile, actionList, actionBuild, actionPath, actionUninstall, actionCompile,
actionCustom actionCustom
@ -56,7 +56,7 @@ type
packages: seq[PkgTuple] # Optional only for actionInstall. packages: seq[PkgTuple] # Optional only for actionInstall.
of actionSearch: of actionSearch:
search: seq[string] # Search string. search: seq[string] # Search string.
of actionInit: of actionInit, actionDump:
projName: string projName: string
of actionCompile: of actionCompile:
file: string file: string
@ -89,6 +89,8 @@ Commands:
[-i, --installed] Lists all installed packages. [-i, --installed] Lists all installed packages.
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
external tools.
Options: Options:
-h, --help Print this help message. -h, --help Print this help message.
@ -188,6 +190,9 @@ proc parseCmdLine(): Options =
of "init": of "init":
result.action.typ = actionInit result.action.typ = actionInit
result.action.projName = "" result.action.projName = ""
of "dump":
result.action.typ = actionDump
result.action.projName = ""
of "update": of "update":
result.action.typ = actionUpdate result.action.typ = actionUpdate
result.action.optionalURL = "" result.action.optionalURL = ""
@ -220,14 +225,14 @@ proc parseCmdLine(): Options =
result.action.optionalURL = key result.action.optionalURL = key
of actionSearch: of actionSearch:
result.action.search.add(key) result.action.search.add(key)
of actionInit: of actionInit, actionDump:
if result.action.projName != "": if result.action.projName != "":
raise newException(NimbleError, raise newException(NimbleError,
"Can only initialize one package at a time.") "Can only initialize one package at a time.")
result.action.projName = key result.action.projName = key
of actionCompile: of actionCompile:
result.action.file = key result.action.file = key
of actionList, actionBuild: of actionList, actionBuild, actionPublish:
writeHelp() writeHelp()
else: else:
discard discard
@ -863,6 +868,33 @@ proc guessAuthor(): string =
return output.string.strip return output.string.strip
return "Anonymous" return "Anonymous"
proc join(x: seq[PkgTuple]; y: string): string =
result = x[0][0] & " " & $x[0][1]
for i in 1 ..< x.len:
result.add y
result.add x[i][0] & " " & $x[i][1]
proc dump(opt: Options) =
let proj = addFileExt(opt.action.projName, NimsExt)
let p = if fileExists(proj): readPackageInfo((true, proj))
else: getPkgInfo(os.getCurrentDir())
echo "name: ", p.name.escape
echo "version: ", p.version.escape
echo "author: ", p.author.escape
echo "desc: ", p.description.escape
echo "license: ", p.license.escape
echo "skipDirs: ", p.skipDirs.join(", ").escape
echo "skipFiles: ", p.skipFiles.join(", ").escape
echo "skipExt: ", p.skipExt.join(", ").escape
echo "installDirs: ", p.installDirs.join(", ").escape
echo "installFiles: ", p.installFiles.join(", ").escape
echo "installExt: ", p.installExt.join(", ").escape
echo "requires: ", p.requires.join(", ").escape
echo "bin: ", p.bin.join(", ").escape
echo "binDir: ", p.binDir.escape
echo "srcDir: ", p.srcDir.escape
echo "backend: ", p.backend.escape
proc init(opt: Options) = proc init(opt: Options) =
echo("Initializing new Nimble project!") echo("Initializing new Nimble project!")
var var
@ -992,6 +1024,8 @@ proc doAction(opt: Options) =
of "publish": of "publish":
var pkgInfo = getPkgInfo(getCurrentDir()) var pkgInfo = getPkgInfo(getCurrentDir())
publish(pkgInfo) publish(pkgInfo)
of "dump":
dump(opt)
of "nop": discard of "nop": discard
else: else:
raise newException(NimbleError, "Unknown command: " & getCommand()) raise newException(NimbleError, "Unknown command: " & getCommand())