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
path: root/lib
diff options
context:
space:
mode:
authorKat Marchán <kzm@sykosomatic.org>2015-07-21 03:52:51 +0300
committerRebecca Turner <me@re-becca.org>2015-08-14 22:25:46 +0300
commite6b5acc3521e074b86c0ea5aad0a836b09d9d164 (patch)
tree841a57c36ec731b7fcde1ba14e9c10c1f991e0bd /lib
parente3b271a7b4bfec856642570d0bf21aed2378737b (diff)
team: initial implementation of team command
PR-URL: https://github.com/npm/npm/pull/9011
Diffstat (limited to 'lib')
-rw-r--r--lib/npm.js1
-rw-r--r--lib/team.js54
2 files changed, 55 insertions, 0 deletions
diff --git a/lib/npm.js b/lib/npm.js
index b92e15266..264ad3636 100644
--- a/lib/npm.js
+++ b/lib/npm.js
@@ -122,6 +122,7 @@
'unpublish',
'owner',
'access',
+ 'team',
'deprecate',
'shrinkwrap',
diff --git a/lib/team.js b/lib/team.js
new file mode 100644
index 000000000..324d8df5e
--- /dev/null
+++ b/lib/team.js
@@ -0,0 +1,54 @@
+var mapToRegistry = require('./utils/map-to-registry.js')
+var npm = require('./npm')
+
+module.exports = team
+
+team.subcommands = ['create', 'destroy', 'add', 'rm', 'ls', 'edit']
+
+team.usage =
+ 'npm team create <scope:team>\n' +
+ 'npm team destroy <scope:team>\n' +
+ 'npm team add <scope:team> <user>\n' +
+ 'npm team rm <scope:team> <user>\n' +
+ 'npm team ls <scope>|<scope:team>\n' +
+ 'npm team edit <scope:team>'
+
+team.completion = function (opts, cb) {
+ var argv = opts.conf.argv.remain
+ if (argv.length === 2) {
+ return cb(null, team.subcommands)
+ }
+ switch (argv[2]) {
+ case 'ls':
+ case 'create':
+ case 'destroy':
+ case 'add':
+ case 'rm':
+ case 'edit':
+ return cb(null, [])
+ default:
+ return cb(new Error(argv[2] + ' not recognized'))
+ }
+}
+
+function team (args, cb) {
+ // Entities are in the format <scope>:<team>
+ var cmd = args.shift()
+ var entity = (args.shift() || '').split(':')
+ return mapToRegistry('/', npm.config, function (err, uri, auth) {
+ if (err) { return cb(err) }
+ try {
+ return npm.registry.team(cmd, uri, {
+ auth: auth,
+ scope: entity[0],
+ team: entity[1],
+ user: args.shift()
+ }, function (err, data) {
+ !err && data && console.log(JSON.stringify(data, undefined, 2))
+ cb(err, data)
+ })
+ } catch (e) {
+ cb(e.message + '\n\nUsage:\n' + team.usage)
+ }
+ })
+}