Skip to content
Browse files

snapshot

  • Loading branch information...
1 parent fbbfbb5 commit 51d53c49b93908257510448cdd2a3ace4b8178a4 @isaacs isaacs committed Nov 30, 2010
Showing with 26 additions and 8 deletions.
  1. +26 −8 lib/ls.js
View
34 lib/ls.js
@@ -13,28 +13,46 @@ var npm = require("../npm")
ls.usage = "npm ls [some search terms ...]"
ls.completion = function (args, index, cb) {
- var compl = ["installed","remote","active"]
+ var compl = []
, getCompletions = require("./utils/completion/get-completions")
- , name = (args.length + 1 === index) ? args[args.length - 1] : ""
- if (name === undefined) name = ""
+ , name = (args.length + 1 === index) && args[args.length - 1] || ""
+ , priors = name ? args.slice(0, args.length - 1) : args
+ log.warn(priors, "addToCompl")
+ function addToCompl (c) {
+ // now, if there are prior args, make sure this line would pass
+ var pass = true
+ for (var i = 0, l = priors.length; i < l; i ++) {
+ pass = false
+ for (var ii = 0, ll = c.length; ii < ll; ii ++) {
+ if (priors[i].indexOf(c[ii]) !== -1) {
+ pass = true
+ break
+ }
+ }
+ if (!pass) break
+ }
+ if (pass) compl = compl.concat(c)
+ }
+ addToCompl(["installed","remote","active"])
getData(3600, function (er, remote, installed) {
if (er) return cb(er)
Object.keys(remote).forEach(function (p) {
var pkg = remote[p]
- compl.push(p)
- compl = compl.concat(pkg.maintainers.map(function (m) {
+ , c = [p, "remote"]
+ c = c.concat(pkg.maintainers.map(function (m) {
return "="+m.name
}))
if (pkg.url && !pkg.versions) {
- compl.push(pkg.url)
+ c.push(pkg.url)
return
}
- compl = compl.concat(Object.keys(pkg.versions).map(function (v) {
+ c = c.concat(Object.keys(pkg.versions).map(function (v) {
return p + "@" + v
}))
- compl = compl.concat(Object.keys(pkg["dist-tags"]).map(function (t) {
+ c = c.concat(Object.keys(pkg["dist-tags"]).map(function (t) {
return t
}))
+ addToCompl(c)
})
Object.keys(installed).forEach(function (p) {
var pkg = installed[p]

0 comments on commit 51d53c4

Please sign in to comment.
Something went wrong with that request. Please try again.