Version querying is now disabled by default.

This commit is contained in:
Dominik Picheta 2013-12-14 17:52:04 +00:00
commit 1646f45111
3 changed files with 43 additions and 28 deletions

View file

@ -8,6 +8,7 @@ import packageinfo, version, common, tools, download, algorithm
type
TOptions = object
forcePrompts: TForcePrompt
queryVersions: bool
action: TAction
TActionType = enum
@ -33,18 +34,23 @@ const
Usage: babel COMMAND [opts]
Commands:
install [pkgname, ...] Installs a list of packages.
build Builds a package.
update [url] Updates package list. A package list URL can be optionally specified.
search pkg/tag Searches for a specified package. Search is performed by tag and by name.
list Lists all packages.
path [pkgname, ...] Shows absolute path to the installed packages.
install [pkgname, ...] Installs a list of packages.
build Builds a package.
update [url] Updates package list. A package list URL can
be optionally specified.
search [--ver] pkg/tag Searches for a specified package. Search is
performed by tag and by name.
list [--ver] Lists all packages.
path pkgname ... Shows absolute path to the installed packages
specified.
Options:
-h, -help Print this help message.
-v, -version Print version information.
-y, -accept Accept all interactive prompts.
-n, -reject Reject all interactive prompts.
-h, --help Print this help message.
-v, --version Print version information.
-y, --accept Accept all interactive prompts.
-n, --reject Reject all interactive prompts.
--ver Query remote server for package version
information when searching or listing packages
"""
babelVersion = "0.1.0"
defaultPackageURL = "https://github.com/nimrod-code/packages/raw/master/packages.json"
@ -99,6 +105,7 @@ proc parseCmdLine(): TOptions =
of "version", "v": writeVersion()
of "accept", "y": result.forcePrompts = ForcePromptYes
of "reject", "n": result.forcePrompts = ForcePromptNo
of "ver": result.queryVersions = true
of cmdEnd: assert(false) # cannot happen
if result.action.typ == ActionNil:
writeHelp()
@ -351,13 +358,12 @@ proc build(options: TOptions) =
let paths = processDeps(pkginfo, options)
buildFromDir(pkgInfo, paths)
proc search(action: TAction) =
## Searches for matches in ``action.search``.
proc search(options: TOptions) =
## Searches for matches in ``options.action.search``.
##
## Searches are done in a case insensitive way making all strings lower case.
## This requires the input search to already be lower case.
assert action.typ == ActionSearch
if action.search == @[]:
assert options.action.typ == ActionSearch
if options.action.search == @[]:
raise newException(EBabel, "Please specify a search string.")
if not existsFile(babelDir / "packages.json"):
raise newException(EBabel, "Please run babel update.")
@ -365,12 +371,14 @@ proc search(action: TAction) =
var found = false
template onFound: stmt =
echoPackage(pkg)
if options.queryVersions:
echoPackageVersions(pkg)
echo(" ")
found = true
break
for pkg in pkgList:
for word in action.search:
for word in options.action.search:
# Search by name.
if word.toLower() in pkg.name.toLower():
onFound()
@ -432,7 +440,7 @@ proc doAction(options: TOptions) =
# TODO: Allow user to specify version.
install(options.action.optionalName, PVersionRange(kind: verAny), options)
of ActionSearch:
search(options.action)
search(options)
of ActionList:
list()
of ActionPath:

View file

@ -152,23 +152,21 @@ proc doDownload*(pkg: TPackage, downloadDir: string, verRange: PVersionRange) =
"Git HEAD also does not satisfy version range: " & $verRange)
# We use GIT HEAD if it satisfies our ver range
proc echoPackage*(pkg: TPackage) =
echo(pkg.name & ":")
echo(" url: " & pkg.url & " (" & pkg.downloadMethod & ")")
echo(" tags: " & pkg.tags.join(", "))
echo(" description: " & pkg.description)
echo(" license: " & pkg.license)
if pkg.web.len > 0:
echo(" website: " & pkg.web)
proc echoPackageVersions*(pkg: TPackage) =
let downMethod = pkg.downloadMethod.getDownloadMethod()
case downMethod
of TDownloadMethod.Git:
try:
let versions = getTagsListRemote(pkg.url, downMethod).getVersionList()
if versions.len > 0:
echo(" versions: ")
for k, ver in versions:
echo " ", ver
var vstr = ""
var i = 0
for v in values(versions):
if i != 0:
vstr.add(", ")
vstr.add(v)
i.inc
echo(" versions: " & vstr)
else:
echo(" versions: (No versions tagged in the remote repository)")
except EOS:

View file

@ -264,3 +264,12 @@ proc getRealDir*(pkgInfo: TPackageInfo): string =
result = pkgInfo.mypath.splitFile.dir / pkgInfo.srcDir
else:
result = pkgInfo.mypath.splitFile.dir
proc echoPackage*(pkg: TPackage) =
echo(pkg.name & ":")
echo(" url: " & pkg.url & " (" & pkg.downloadMethod & ")")
echo(" tags: " & pkg.tags.join(", "))
echo(" description: " & pkg.description)
echo(" license: " & pkg.license)
if pkg.web.len > 0:
echo(" website: " & pkg.web)