Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release: npm@6.7.0 #141

Merged
merged 15 commits into from
Jan 23, 2019
Prev Previous commit
Next Next commit
org: improve usage errors and add org ls filtering
  • Loading branch information
zkat committed Jan 18, 2019
commit 50463f58b4b70180a85d6d8c10fcf50d8970ef5e
36 changes: 31 additions & 5 deletions lib/org.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ org.subcommands = ['set', 'rm', 'ls']
org.usage =
'npm org set orgname username [developer | admin | owner]\n' +
'npm org rm orgname username\n' +
'npm org ls orgname'
'npm org ls orgname [<username>]'

const OrgConfig = figgyPudding({
json: {},
Expand Down Expand Up @@ -53,17 +53,27 @@ function org ([cmd, orgname, username, role], cb) {
case 'rm':
return orgRm(orgname, username, opts)
case 'ls':
return orgList(orgname, opts)
return orgList(orgname, username, opts)
default:
UsageError()
}
}).then(
x => cb(null, x),
err => err.code === 'EUSAGE' ? err.message : err
).catch(cb)
err => cb(err.code === 'EUSAGE' ? err.message : err)
)
}

function orgSet (org, user, role, opts) {
role = role || 'developer'
if (!org) {
throw new Error('First argument `orgname` is required.')
}
if (!user) {
throw new Error('Second argument `username` is required.')
}
if (!['owner', 'admin', 'developer'].find(role)) {
throw new Error('Third argument `role` must be one of `owner`, `admin`, or `developer`, with `developer` being the default value if omitted.')
}
return liborg.set(org, user, role, opts).then(memDeets => {
if (opts.json) {
output(JSON.stringify(memDeets, null, 2))
Expand All @@ -83,6 +93,12 @@ function orgSet (org, user, role, opts) {
}

function orgRm (org, user, opts) {
if (!org) {
throw new Error('First argument `orgname` is required.')
}
if (!user) {
throw new Error('Second argument `username` is required.')
}
return liborg.rm(org, user, opts).then(() => {
return liborg.ls(org, opts)
}).then(roster => {
Expand All @@ -105,8 +121,18 @@ function orgRm (org, user, opts) {
})
}

function orgList (org, opts) {
function orgList (org, user, opts) {
if (!org) {
throw new Error('First argument `orgname` is required.')
}
return liborg.ls(org, opts).then(roster => {
if (user) {
const newRoster = {}
if (roster[user]) {
newRoster[user] = roster[user]
}
roster = newRoster
}
if (opts.json) {
output(JSON.stringify(roster, null, 2))
} else if (opts.parseable) {
Expand Down