Implemented list feature.
This commit is contained in:
parent
c732892116
commit
41da5f70ae
1 changed files with 17 additions and 4 deletions
21
babel.nim
21
babel.nim
|
|
@ -4,18 +4,17 @@ import packageinfo
|
||||||
|
|
||||||
type
|
type
|
||||||
TActionType = enum
|
TActionType = enum
|
||||||
ActionNil, ActionUpdate, ActionInstall, ActionSearch
|
ActionNil, ActionUpdate, ActionInstall, ActionSearch, ActionList
|
||||||
|
|
||||||
TAction = object
|
TAction = object
|
||||||
case typ: TActionType
|
case typ: TActionType
|
||||||
of ActionNil: nil
|
of ActionNil, ActionList: nil
|
||||||
of ActionUpdate:
|
of ActionUpdate:
|
||||||
optionalURL: string # Overrides default package list.
|
optionalURL: string # Overrides default package list.
|
||||||
of ActionInstall:
|
of ActionInstall:
|
||||||
optionalName: seq[string] # When this is @[], installs package from current dir.
|
optionalName: seq[string] # When this is @[], installs package from current dir.
|
||||||
of ActionSearch:
|
of ActionSearch:
|
||||||
search: seq[string] # Search string.
|
search: seq[string] # Search string.
|
||||||
byTag: bool
|
|
||||||
|
|
||||||
const
|
const
|
||||||
help = """
|
help = """
|
||||||
|
|
@ -25,6 +24,7 @@ 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.
|
||||||
|
list Lists all packages.
|
||||||
"""
|
"""
|
||||||
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"
|
||||||
|
|
@ -53,7 +53,8 @@ proc parseCmdLine(): TAction =
|
||||||
of "search":
|
of "search":
|
||||||
result.typ = ActionSearch
|
result.typ = ActionSearch
|
||||||
result.search = @[]
|
result.search = @[]
|
||||||
result.byTag = false
|
of "list":
|
||||||
|
result.typ = ActionList
|
||||||
else: writeHelp()
|
else: writeHelp()
|
||||||
else:
|
else:
|
||||||
case result.typ
|
case result.typ
|
||||||
|
|
@ -65,6 +66,8 @@ proc parseCmdLine(): TAction =
|
||||||
result.optionalURL = key
|
result.optionalURL = key
|
||||||
of ActionSearch:
|
of ActionSearch:
|
||||||
result.search.add(key)
|
result.search.add(key)
|
||||||
|
of ActionList:
|
||||||
|
writeHelp()
|
||||||
of cmdLongOption, cmdShortOption:
|
of cmdLongOption, cmdShortOption:
|
||||||
case key
|
case key
|
||||||
of "help", "h": writeHelp()
|
of "help", "h": writeHelp()
|
||||||
|
|
@ -230,6 +233,14 @@ proc search(action: TAction) =
|
||||||
if notFound:
|
if notFound:
|
||||||
echo("No package found.")
|
echo("No package found.")
|
||||||
|
|
||||||
|
proc list =
|
||||||
|
if not existsFile(getBabelDir() / "packages.json"):
|
||||||
|
quit("Please run babel update.", QuitFailure)
|
||||||
|
let pkgList = getPackageList(getBabelDir() / "packages.json")
|
||||||
|
for pkg in pkgList:
|
||||||
|
echoPackage(pkg)
|
||||||
|
echo(" ")
|
||||||
|
|
||||||
proc doAction(action: TAction) =
|
proc doAction(action: TAction) =
|
||||||
case action.typ
|
case action.typ
|
||||||
of ActionUpdate:
|
of ActionUpdate:
|
||||||
|
|
@ -241,6 +252,8 @@ proc doAction(action: TAction) =
|
||||||
install(action.optionalName)
|
install(action.optionalName)
|
||||||
of ActionSearch:
|
of ActionSearch:
|
||||||
search(action)
|
search(action)
|
||||||
|
of ActionList:
|
||||||
|
list()
|
||||||
of ActionNil:
|
of ActionNil:
|
||||||
assert false
|
assert false
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue