diff options
author | isaacs <i@izs.me> | 2011-03-16 23:38:38 +0300 |
---|---|---|
committer | isaacs <i@izs.me> | 2011-03-22 01:56:14 +0300 |
commit | 0d6b8c08ff8883d46c280f10e4524b0787d24338 (patch) | |
tree | 7887b52863eb50793e5518b1086427700b8e1e3b /lib/unpublish.js | |
parent | ef912008e1050e9058195937e91aae53787c8672 (diff) |
completion for unpublish
Diffstat (limited to 'lib/unpublish.js')
-rw-r--r-- | lib/unpublish.js | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/lib/unpublish.js b/lib/unpublish.js index 8664cef24..96f64ada3 100644 --- a/lib/unpublish.js +++ b/lib/unpublish.js @@ -9,9 +9,32 @@ var registry = require("./utils/npm-registry-client") unpublish.usage = "npm unpublish <project>[@<version>]" -unpublish.completion = function (args, index, cb) { - var remotePkgs = require("./utils/completion/remote-packages") - remotePkgs(args, index, true, false, false, cb) +unpublish.completion = function (opts, cb) { + if (opts.conf.argv.remain.length >= 3) return cb() + var un = encodeURIComponent(npm.config.get("username")) + if (!un) return cb() + registry.get("/-/by-user/"+un, function (er, pkgs) { + // do a bit of filtering at this point, so that we don't need + // to fetch versions for more than one thing, but also don't + // accidentally a whole project. + pkgs = pkgs[un] + if (!pkgs || !pkgs.length) return cb() + var partial = opts.partialWord.split("@") + , pp = partial.shift() + , pv = partial.join("@") + pkgs = pkgs.filter(function (p) { + return p.indexOf(pp) === 0 + }) + if (pkgs.length > 1) return cb(null, pkgs) + registry.get(pkgs[0], function (er, d) { + if (er) return cb(er) + var vers = Object.keys(d.versions) + if (!vers.length) return cb(null, pkgs) + return cb(null, vers.map(function (v) { + return pkgs[0]+"@"+v + })) + }) + }) } function unpublish (args, cb) { |