Adds support for optional web field.

This change makes nimrod-code/packages#31 useful.
This commit is contained in:
Grzegorz Adam Hankiewicz 2013-11-08 11:36:58 +01:00
commit 37b8c46b3b

View file

@ -22,14 +22,17 @@ type
backend*: string backend*: string
TPackage* = object TPackage* = object
# Required fields in a package.
name*: string name*: string
version*: string url*: string # Download location.
license*: string license*: string
url*: string
dvcsTag*: string
downloadMethod*: string downloadMethod*: string
tags*: seq[string]
description*: string description*: string
tags*: seq[string] # Even if empty, always a valid non nil seq. \
# From here on, optional fields set to the emtpy string if not available.
version*: string
dvcsTag*: string
web*: string # Info url for humans.
proc initPackageInfo(): TPackageInfo = proc initPackageInfo(): TPackageInfo =
result.mypath = "" result.mypath = ""
@ -168,6 +171,7 @@ proc getPackage*(pkg: string, packagesPath: string, resPkg: var TPackage): bool
for t in p["tags"]: for t in p["tags"]:
resPkg.tags.add(t.str) resPkg.tags.add(t.str)
resPkg.description = p.requiredField("description") resPkg.description = p.requiredField("description")
resPkg.web = p.optionalField("web")
return true return true
return false return false
@ -186,6 +190,7 @@ proc getPackageList*(packagesPath: string): seq[TPackage] =
for t in p["tags"]: for t in p["tags"]:
pkg.tags.add(t.str) pkg.tags.add(t.str)
pkg.description = p.requiredField("description") pkg.description = p.requiredField("description")
pkg.web = p.optionalField("web")
result.add(pkg) result.add(pkg)
proc findBabelFile*(dir: string): string = proc findBabelFile*(dir: string): string =
@ -245,3 +250,5 @@ proc echoPackage*(pkg: TPackage) =
echo(" tags: " & pkg.tags.join(", ")) echo(" tags: " & pkg.tags.join(", "))
echo(" description: " & pkg.description) echo(" description: " & pkg.description)
echo(" license: " & pkg.license) echo(" license: " & pkg.license)
if pkg.web.len > 0:
echo(" website: " & pkg.web)