-
Notifications
You must be signed in to change notification settings - Fork 115
/
Copy pathncu-team.js
executable file
·76 lines (68 loc) · 1.73 KB
/
ncu-team.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env node
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';
import Request from '../lib/request.js';
import auth from '../lib/auth.js';
import { runPromise } from '../lib/run.js';
import CLI from '../lib/cli.js';
import TeamInfo from '../lib/team_info.js';
import { setVerbosityFromEnv } from '../lib/verbosity.js';
setVerbosityFromEnv();
yargs(hideBin(process.argv))
.completion('completion')
.command({
command: 'list <team> [org]',
desc: 'Get the list of members in a team',
builder: (yargs) => {
yargs
.positional('team', {
describe: 'Name of the team',
type: 'string'
})
.positional('org', {
describe: 'Name of the organization',
type: 'string',
default: 'nodejs'
});
},
handler
})
.command({
command: 'sync <file>',
desc:
'Synchronize the <!-- ncu-team-sync.team($org/$team) --> block in a file',
builder: (yargs) => {
yargs
.positional('file', {
describe: 'Path to the file to update',
type: 'string'
});
},
handler
})
.demandCommand(1, 'must provide a valid command')
.help()
.parse();
function handler(argv) {
runPromise(main(argv));
}
async function main(argv) {
const cli = new CLI();
const credentials = await auth({
github: true
});
const request = new Request(credentials);
const [command] = argv._;
switch (command) {
case 'list': {
const info = new TeamInfo(cli, request, argv.org, argv.team);
await info.listMembers();
break;
}
case 'sync':
await TeamInfo.syncFile(cli, request, argv.file);
break;
default:
throw new Error(`Unknown command ${command}`);
}
}