3 var assert = require('assert')
4 var url = require('url')
8 function team (sub, uri, params, cb) {
9 teamAssertions(sub, uri, params, cb)
10 return subcommands[sub].call(this, uri, params, cb)
13 subcommands.create = function (uri, params, cb) {
14 return this.request(apiUri(uri, 'org', params.scope, 'team'), {
17 body: JSON.stringify({
23 subcommands.destroy = function (uri, params, cb) {
24 return this.request(apiUri(uri, 'team', params.scope, params.team), {
30 subcommands.add = function (uri, params, cb) {
31 return this.request(apiUri(uri, 'team', params.scope, params.team, 'user'), {
34 body: JSON.stringify({
40 subcommands.rm = function (uri, params, cb) {
41 return this.request(apiUri(uri, 'team', params.scope, params.team, 'user'), {
44 body: JSON.stringify({
50 subcommands.ls = function (uri, params, cb) {
51 var uriParams = '?format=cli'
54 uri, 'team', params.scope, params.team, 'user') + uriParams
55 return this.request(reqUri, {
60 return this.request(apiUri(uri, 'org', params.scope, 'team') + uriParams, {
67 // TODO - we punted this to v2
68 // subcommands.edit = function (uri, params, cb) {
69 // return this.request(apiUri(uri, 'team', params.scope, params.team, 'user'), {
72 // body: JSON.stringify({
73 // users: params.users
78 function apiUri (registryUri) {
79 var path = Array.prototype.slice.call(arguments, 1)
80 .map(encodeURIComponent)
82 return url.resolve(registryUri, '-/' + path)
85 function teamAssertions (subcommand, uri, params, cb) {
86 assert(subcommand, 'subcommand is required')
87 assert(subcommands.hasOwnProperty(subcommand),
88 'team subcommand must be one of ' + Object.keys(subcommands))
89 assert(typeof uri === 'string', 'registry URI is required')
90 assert(typeof params === 'object', 'params are required')
91 assert(typeof params.auth === 'object', 'auth is required')
92 assert(typeof params.scope === 'string', 'scope is required')
93 assert(!cb || typeof cb === 'function', 'callback must be a function')
94 if (subcommand !== 'ls') {
95 assert(typeof params.team === 'string', 'team name is required')
97 if (subcommand === 'rm' || subcommand === 'add') {
98 assert(typeof params.user === 'string', 'user is required')
100 if (subcommand === 'edit') {
101 assert(typeof params.users === 'object' &&
102 params.users.length != null,