Skip to content
This repository was archived by the owner on Jul 28, 2021. It is now read-only.

Commit 038b9aa

Browse files
committed
feat(org): add tink org and subcommands
1 parent 6bc856d commit 038b9aa

File tree

4 files changed

+202
-21
lines changed

4 files changed

+202
-21
lines changed

bin/tink.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ require('../lib/node/index.js')
55
const CMDS = new Map([
66
['sh', require('../lib/commands/shell.js')],
77
['shell', require('../lib/commands/shell.js')],
8+
['org', require('../lib/commands/org.jsx')],
89
['prep', require('../lib/commands/prepare.js')],
910
['prepare', require('../lib/commands/prepare.js')],
1011
['ping', require('../lib/commands/ping.js')]

lib/commands/org.jsx

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
'use strict'
2+
3+
const Org = module.exports = {
4+
command: 'org',
5+
describe: 'org-related subcommands',
6+
builder (y) {
7+
return y.help().alias('help', 'h')
8+
.options(Org.options)
9+
.demandCommand(1, 'Org subcommand is required')
10+
.recommendCommands()
11+
.command(
12+
['add <orgname> <username> [role]', 'set'],
13+
'Add someone to an org',
14+
Org.options,
15+
async argv => orgAdd(argv)
16+
)
17+
.command(
18+
'rm <org> <user>',
19+
'Remove someone from an org',
20+
Org.options,
21+
async argv => orgRm(argv)
22+
)
23+
.command(
24+
'ls <org>',
25+
'List org members',
26+
Org.options,
27+
async argv => orgLs(argv)
28+
)
29+
},
30+
options: Object.assign(require('../common-opts.js', {}))
31+
}
32+
33+
async function orgAdd (argv) {
34+
const figgyPudding = require('figgy-pudding')
35+
const libnpm = require('libnpm')
36+
const npmConfig = require('../config.js')
37+
38+
const OrgConfig = figgyPudding({
39+
json: {},
40+
loglevel: {},
41+
parseable: {},
42+
silent: {}
43+
})
44+
45+
const opts = OrgConfig(npmConfig().concat(argv).concat({
46+
log: require('npmlog')
47+
}))
48+
const memDeets = await libnpm.org.set(argv.org, argv.user, argv.role, opts)
49+
if (opts.json) {
50+
console.log(JSON.stringify(memDeets, null, 2))
51+
} else if (opts.parseable) {
52+
console.log(['org', 'orgsize', 'user', 'role'].join('\t'))
53+
console.log([
54+
memDeets.org.name,
55+
memDeets.org.size,
56+
memDeets.user,
57+
memDeets.role
58+
])
59+
} else if (!opts.silent && opts.loglevel !== 'silent') {
60+
console.log(`Added ${memDeets.user} as ${memDeets.role} to ${memDeets.org.name}. You now ${memDeets.org.size} member${memDeets.org.size === 1 ? '' : 's'} in this org.`)
61+
}
62+
return memDeets
63+
}
64+
65+
async function orgRm (argv) {
66+
const figgyPudding = require('figgy-pudding')
67+
const libnpm = require('libnpm')
68+
const npmConfig = require('../config.js')
69+
70+
const OrgConfig = figgyPudding({
71+
json: {},
72+
loglevel: {},
73+
parseable: {},
74+
silent: {}
75+
})
76+
77+
const opts = OrgConfig(npmConfig().concat(argv).concat({
78+
log: require('npmlog')
79+
}))
80+
await libnpm.org.rm(argv.org, argv.user, opts)
81+
const roster = libnpm.org.ls(argv.org, opts)
82+
const user = argv.user.replace(/^[~@]?/, '')
83+
const org = argv.org.replace(/^[~@]?/, '')
84+
const userCount = Object.keys(roster).length
85+
if (opts.json) {
86+
console.log(JSON.stringify({
87+
user,
88+
org,
89+
userCount,
90+
deleted: true
91+
}))
92+
} else if (opts.parseable) {
93+
console.log(['user', 'org', 'userCount', 'deleted'].join('\t'))
94+
console.log([user, org, userCount, true].join('\t'))
95+
} else if (!opts.silent && opts.loglevel !== 'silent') {
96+
console.log(`Successfully removed ${user} from ${org}. You now have ${userCount} member${userCount === 1 ? '' : 's'} in this org.`)
97+
}
98+
}
99+
100+
async function orgLs (argv) {
101+
const figgyPudding = require('figgy-pudding')
102+
const { h, renderToString } = require('ink')
103+
const libnpm = require('libnpm')
104+
const npmConfig = require('../config.js')
105+
const Table = require('ink-table').default
106+
107+
const OrgConfig = figgyPudding({
108+
json: {},
109+
loglevel: {},
110+
parseable: {},
111+
silent: {}
112+
})
113+
114+
const opts = OrgConfig(npmConfig().concat(argv).concat({
115+
log: require('npmlog')
116+
}))
117+
const roster = await libnpm.org.ls(argv.org, opts)
118+
if (opts.json) {
119+
console.log(JSON.stringify(roster, null, 2))
120+
} else if (opts.parseable) {
121+
console.log(['user', 'role'].join('\t'))
122+
Object.keys(roster).forEach(user => {
123+
console.log([user, roster[user]].join('\t'))
124+
})
125+
} else if (!opts.silent && opts.loglevel !== 'silent') {
126+
const data = Object.keys(roster).map(user => {
127+
return {user, role: roster[user]}
128+
})
129+
console.log(renderToString(<Table data={data}/>))
130+
}
131+
}

package-lock.json

Lines changed: 68 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@
6161
"glob": "^7.1.3",
6262
"graceful-fs": "^4.1.11",
6363
"ini": "^1.3.5",
64+
"ink": "^0.5.1",
65+
"ink-table": "^1.0.3",
6466
"jsx-transform": "^2.4.0",
6567
"libnpm": "^1.3.0",
6668
"lock-verify": "^2.0.2",

0 commit comments

Comments
 (0)