Search now searches by name and tags.
This commit is contained in:
parent
1db1592bca
commit
69f28c2c2f
1 changed files with 20 additions and 25 deletions
45
babel.nim
45
babel.nim
|
|
@ -25,9 +25,6 @@ Commands:
|
||||||
install Installs a list of packages.
|
install Installs a list of packages.
|
||||||
update Updates package list. A package list URL can be optionally specificed.
|
update Updates package list. A package list URL can be optionally specificed.
|
||||||
search Searches for a specified package.
|
search Searches for a specified package.
|
||||||
|
|
||||||
Search:
|
|
||||||
--tags Searches by tags, otherwise by name.
|
|
||||||
"""
|
"""
|
||||||
babelVersion = "0.1.0"
|
babelVersion = "0.1.0"
|
||||||
defaultPackageURL = "https://github.com/nimrod-code/packages/raw/master/packages.json"
|
defaultPackageURL = "https://github.com/nimrod-code/packages/raw/master/packages.json"
|
||||||
|
|
@ -72,10 +69,6 @@ proc parseCmdLine(): TAction =
|
||||||
case key
|
case key
|
||||||
of "help", "h": writeHelp()
|
of "help", "h": writeHelp()
|
||||||
of "version", "v": writeVersion()
|
of "version", "v": writeVersion()
|
||||||
of "tags", "t":
|
|
||||||
case result.typ
|
|
||||||
of ActionSearch: result.byTag = true
|
|
||||||
else: writeHelp()
|
|
||||||
of cmdEnd: assert(false) # cannot happen
|
of cmdEnd: assert(false) # cannot happen
|
||||||
if result.typ == ActionNil:
|
if result.typ == ActionNil:
|
||||||
writeHelp()
|
writeHelp()
|
||||||
|
|
@ -91,9 +84,13 @@ proc prompt(question: string): bool =
|
||||||
else:
|
else:
|
||||||
return false
|
return false
|
||||||
|
|
||||||
|
proc getBabelDir: string = return getHomeDir() / "babel"
|
||||||
|
|
||||||
|
proc getLibsDir: string = return getBabelDir() / "libs"
|
||||||
|
|
||||||
proc update(url: string = defaultPackageURL) =
|
proc update(url: string = defaultPackageURL) =
|
||||||
echo("Downloading package list from " & url)
|
echo("Downloading package list from " & url)
|
||||||
downloadFile(url, getHomeDir() / ".babel" / "packages.json")
|
downloadFile(url, getBabelDir() / "packages.json")
|
||||||
echo("Done.")
|
echo("Done.")
|
||||||
|
|
||||||
proc findBabelFile(dir: string): string =
|
proc findBabelFile(dir: string): string =
|
||||||
|
|
@ -107,10 +104,6 @@ proc copyFileD(fro, to: string) =
|
||||||
echo(fro, " -> ", to)
|
echo(fro, " -> ", to)
|
||||||
copyFile(fro, to)
|
copyFile(fro, to)
|
||||||
|
|
||||||
proc getBabelDir: string = return getHomeDir() / "babel"
|
|
||||||
|
|
||||||
proc getLibsDir: string = return getBabelDir() / "libs"
|
|
||||||
|
|
||||||
proc samePaths(p1, p2: string): bool =
|
proc samePaths(p1, p2: string): bool =
|
||||||
## Normalizes path (by adding a trailing slash) and compares.
|
## Normalizes path (by adding a trailing slash) and compares.
|
||||||
let cp1 = if not p1.endsWith("/"): p1 & "/" else: p1
|
let cp1 = if not p1.endsWith("/"): p1 & "/" else: p1
|
||||||
|
|
@ -215,17 +208,19 @@ proc search(action: TAction) =
|
||||||
assert action.typ == ActionSearch
|
assert action.typ == ActionSearch
|
||||||
if action.search == @[]:
|
if action.search == @[]:
|
||||||
quit("Please specify a search string.", QuitFailure)
|
quit("Please specify a search string.", QuitFailure)
|
||||||
|
if not existsFile(getBabelDir() / "packages.json"):
|
||||||
|
quit("Please run babel update.", QuitFailure)
|
||||||
let pkgList = getPackageList(getBabelDir() / "packages.json")
|
let pkgList = getPackageList(getBabelDir() / "packages.json")
|
||||||
var notFound = true
|
var notFound = true
|
||||||
if action.byTag:
|
for pkg in pkgList:
|
||||||
for pkg in pkgList:
|
for word in action.search:
|
||||||
for word in action.search:
|
if word in pkg.tags:
|
||||||
if word in pkg.tags:
|
echoPackage(pkg)
|
||||||
echoPackage(pkg)
|
echo(" ")
|
||||||
echo(" ")
|
notFound = false
|
||||||
notFound = false
|
break
|
||||||
break
|
if notFound:
|
||||||
else:
|
# Search by tag.
|
||||||
for pkg in pkgList:
|
for pkg in pkgList:
|
||||||
if pkg.name in action.search:
|
if pkg.name in action.search:
|
||||||
echoPackage(pkg)
|
echoPackage(pkg)
|
||||||
|
|
@ -250,10 +245,10 @@ proc doAction(action: TAction) =
|
||||||
assert false
|
assert false
|
||||||
|
|
||||||
when isMainModule:
|
when isMainModule:
|
||||||
if not existsDir(getHomeDir() / ".babel"):
|
if not existsDir(getBabelDir()):
|
||||||
createDir(getHomeDir() / ".babel")
|
createDir(getBabelDir())
|
||||||
if not existsDir(getHomeDir() / ".babel" / "libs"):
|
if not existsDir(getLibsDir()):
|
||||||
createDir(getHomeDir() / ".babel" / "libs")
|
createDir(getLibsDir())
|
||||||
|
|
||||||
parseCmdLine().doAction()
|
parseCmdLine().doAction()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue