From e6b5acc3521e074b86c0ea5aad0a836b09d9d164 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kat=20March=C3=A1n?= Date: Mon, 20 Jul 2015 17:52:51 -0700 Subject: team: initial implementation of team command PR-URL: https://github.com/npm/npm/pull/9011 --- lib/npm.js | 1 + lib/team.js | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 lib/team.js (limited to 'lib') 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 \n' + + 'npm team destroy \n' + + 'npm team add \n' + + 'npm team rm \n' + + 'npm team ls |\n' + + 'npm team edit ' + +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 : + 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) + } + }) +} -- cgit v1.2.3