@@ -14,7 +14,7 @@ org.subcommands = ['set', 'rm', 'ls']
14
14
org . usage =
15
15
'npm org set orgname username [developer | admin | owner]\n' +
16
16
'npm org rm orgname username\n' +
17
- 'npm org ls orgname'
17
+ 'npm org ls orgname [<username>] '
18
18
19
19
const OrgConfig = figgyPudding ( {
20
20
json : { } ,
@@ -53,17 +53,27 @@ function org ([cmd, orgname, username, role], cb) {
53
53
case 'rm' :
54
54
return orgRm ( orgname , username , opts )
55
55
case 'ls' :
56
- return orgList ( orgname , opts )
56
+ return orgList ( orgname , username , opts )
57
57
default :
58
58
UsageError ( )
59
59
}
60
60
} ) . then (
61
61
x => cb ( null , x ) ,
62
- err => err . code === 'EUSAGE' ? err . message : err
63
- ) . catch ( cb )
62
+ err => cb ( err . code === 'EUSAGE' ? err . message : err )
63
+ )
64
64
}
65
65
66
66
function orgSet ( org , user , role , opts ) {
67
+ role = role || 'developer'
68
+ if ( ! org ) {
69
+ throw new Error ( 'First argument `orgname` is required.' )
70
+ }
71
+ if ( ! user ) {
72
+ throw new Error ( 'Second argument `username` is required.' )
73
+ }
74
+ if ( ! [ 'owner' , 'admin' , 'developer' ] . find ( role ) ) {
75
+ throw new Error ( 'Third argument `role` must be one of `owner`, `admin`, or `developer`, with `developer` being the default value if omitted.' )
76
+ }
67
77
return liborg . set ( org , user , role , opts ) . then ( memDeets => {
68
78
if ( opts . json ) {
69
79
output ( JSON . stringify ( memDeets , null , 2 ) )
@@ -83,6 +93,12 @@ function orgSet (org, user, role, opts) {
83
93
}
84
94
85
95
function orgRm ( org , user , opts ) {
96
+ if ( ! org ) {
97
+ throw new Error ( 'First argument `orgname` is required.' )
98
+ }
99
+ if ( ! user ) {
100
+ throw new Error ( 'Second argument `username` is required.' )
101
+ }
86
102
return liborg . rm ( org , user , opts ) . then ( ( ) => {
87
103
return liborg . ls ( org , opts )
88
104
} ) . then ( roster => {
@@ -105,8 +121,18 @@ function orgRm (org, user, opts) {
105
121
} )
106
122
}
107
123
108
- function orgList ( org , opts ) {
124
+ function orgList ( org , user , opts ) {
125
+ if ( ! org ) {
126
+ throw new Error ( 'First argument `orgname` is required.' )
127
+ }
109
128
return liborg . ls ( org , opts ) . then ( roster => {
129
+ if ( user ) {
130
+ const newRoster = { }
131
+ if ( roster [ user ] ) {
132
+ newRoster [ user ] = roster [ user ]
133
+ }
134
+ roster = newRoster
135
+ }
110
136
if ( opts . json ) {
111
137
output ( JSON . stringify ( roster , null , 2 ) )
112
138
} else if ( opts . parseable ) {
0 commit comments