-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
executable file
·51 lines (41 loc) · 1.08 KB
/
cli.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
#!/usr/bin/env node
/* eslint-disable no-console */
'use strict'
const yaml = require('js-yaml')
const { ArgumentParser } = require('argparse')
const { prettify, rateLimitForClientId, rateLimitForToken } = require('.')
async function main(inArgs) {
const parser = new ArgumentParser({
description: 'Troubleshoot GitHub rate limits',
})
parser.addArgument(['-c', '--client'], {
nargs: 2,
metavar: ['CLIENT_ID', 'CLIENT_SECRET'],
help: 'GitHub client ID and secret',
})
parser.addArgument(['-t', '--token'], { help: 'GitHub token' })
const args = parser.parseArgs(inArgs)
if (!args.client && !args.token) {
parser.printUsage()
process.exit(1)
}
let result
if (args.client) {
result = await rateLimitForClientId(...args.client)
} else {
result = await rateLimitForToken(args.token)
}
const prettified = prettify(result)
console.log(yaml.safeDump(prettified))
}
module.exports = main
if (require.main === module) {
;(async () => {
try {
await main()
} catch (e) {
console.error(e)
process.exit(1)
}
})()
}