Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorisaacs <i@izs.me>2011-03-16 22:50:47 +0300
committerisaacs <i@izs.me>2011-03-22 01:56:14 +0300
commiteecfd3c7a9c75cf6ee985b716944495e2dfd5d1a (patch)
tree7e13ab1be778c97176178e4d7dd7bf72b27151dc /lib/owner.js
parent78e3a2686115fa2e798aadbab703d34e0ab594e7 (diff)
completion for owner command
Diffstat (limited to 'lib/owner.js')
-rw-r--r--lib/owner.js71
1 files changed, 55 insertions, 16 deletions
diff --git a/lib/owner.js b/lib/owner.js
index 4c183f5aa..34709cf4e 100644
--- a/lib/owner.js
+++ b/lib/owner.js
@@ -5,24 +5,63 @@ owner.usage = "npm owner add <username> <pkg>"
+ "\nnpm owner rm <username> <pkg>"
+ "\nnpm owner ls <pkg>"
-owner.completion = function(args, index, cb) {
- var remotePkgs = require("./utils/completion/remote-packages")
- , getCompletions = require("./utils/completion/get-completions")
- , subcmdList = ["add", "ls", "rm"]
- , subcmd = args[0] || ""
- , users = require("./utils/completion/users")
+owner.completion = function (opts, cb) {
+ var argv = opts.conf.argv.remain
+ if (argv.length > 4) return cb()
+ if (argv.length <= 2) {
+ var subs = ["add", "rm"]
+ if (opts.partialWord === "l") subs.push("ls")
+ else subs.push("ls", "list")
+ return cb(null, subs)
+ }
+ var un = encodeURIComponent(npm.config.get("username"))
+ switch (argv[2]) {
+ case "ls":
+ if (argv.length > 3) return cb()
+ else return registry.get("/-/short", cb)
- if (subcmdList.indexOf(subcmd) !== -1) {
- if (subcmd === "ls") {
- remotePkgs(args.slice(1), index - 1, false, false, false, cb)
- } else if (subcmd === "add" || subcmd === "rm") {
- if (index === 4) {
- remotePkgs(args.slice(2), index - 2, false, false, false, cb)
- } else {
- users(args.slice(1), index - 1, cb)
+ case "rm":
+ if (argv.length > 3) {
+ var theUser = encodeURIComponent(argv[3])
+ , uri = "/-/by-user/"+theUser+"|"+un
+ console.error(uri)
+ return registry.get(uri, function (er, d) {
+ if (er) return cb(er)
+ // return the intersection
+ return cb(null, d[theUser].filter(function (p) {
+ // kludge for server adminery.
+ return un === "isaacs" || d[un].indexOf(p) === -1
+ }))
+ })
}
- }
- } else cb(null, getCompletions(subcmd, subcmdList))
+ // else fallthrough
+ case "add":
+ if (argv.length > 3) {
+ var theUser = encodeURIComponent(argv[3])
+ , uri = "/-/by-user/"+theUser+"|"+un
+ console.error(uri)
+ return registry.get(uri, function (er, d) {
+ console.error(uri, er || d)
+ // return mine that they're not already on.
+ if (er) return cb(er)
+ var mine = d[un] || []
+ , theirs = d[theUser] || []
+ return cb(null, mine.filter(function (p) {
+ return theirs.indexOf(p) === -1
+ }))
+ })
+ }
+ // just list all users who aren't me.
+ return registry.get("/-/users", function (er, list) {
+ if (er) return cb()
+ return cb(null, Object.keys(list).filter(function (n) {
+ return n !== un
+ }))
+ })
+
+ default:
+ return cb()
+ }
}
var registry = require("./utils/npm-registry-client")