Skip to content

Commit

Permalink
Merge pull request #82 from hiteshjasani/master
Browse files Browse the repository at this point in the history
Add command to list installed packages.
  • Loading branch information
dom96 committed Jan 3, 2015
2 parents a0eb724 + a8039a7 commit e6bdf43
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/nimble.nim
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type
TOptions = object
forcePrompts: TForcePrompt
queryVersions: bool
queryInstalled: bool
action: TAction
config: TConfig
nimbleData: PJsonNode ## Nimbledata.json
Expand Down Expand Up @@ -55,6 +56,7 @@ Commands:
search [--ver] pkg/tag Searches for a specified package. Search is
performed by tag and by name.
list [--ver] Lists all packages.
[-i, --installed] Lists all installed packages.
path pkgname ... Shows absolute path to the installed packages
specified.
Expand Down Expand Up @@ -184,6 +186,7 @@ proc parseCmdLine(): TOptions =
of "accept", "y": result.forcePrompts = ForcePromptYes
of "reject", "n": result.forcePrompts = ForcePromptNo
of "ver": result.queryVersions = true
of "installed", "i": result.queryInstalled = true
of cmdEnd: assert(false) # cannot happen
if result.action.typ == ActionNil:
writeHelp()
Expand Down Expand Up @@ -663,6 +666,20 @@ proc list(options: TOptions) =
echoPackageVersions(pkg)
echo(" ")

proc listInstalled(options: TOptions) =
var h = initTable[string, seq[string]]()
let pkgs = getInstalledPkgs(options.getPkgsDir())
for x in pkgs.items():
let
pName = x.pkginfo.name
pVer = x.pkginfo.version
if not h.hasKey(pName): h[pName] = @[]
var s = h[pName]
add(s, pVer)
h[pName] = s
for k in keys(h):
echo k & " [" & h[k].join(", ") & "]"

type VersionAndPath = tuple[version: TVersion, path: string]

proc listPaths(options: TOptions) =
Expand Down Expand Up @@ -814,7 +831,8 @@ proc doAction(options: TOptions) =
of ActionSearch:
search(options)
of ActionList:
list(options)
if options.queryInstalled: listInstalled(options)
else: list(options)
of ActionPath:
listPaths(options)
of ActionBuild:
Expand Down

0 comments on commit e6bdf43

Please sign in to comment.