-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
executable file
·51 lines (40 loc) · 1.49 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
var DISCOURSE_URL = 'https://frm.hackafe.org'
global.CMD_NAME = 'hackafe-meetups'
var optimist = require('optimist')
var rc = require('rc')
process.title = global.CMD_NAME
var argv = rc(global.CMD_NAME, { url: DISCOURSE_URL }, optimist
.usage('Usage: $0 command [options]')
.alias('h', 'host').describe('h', 'url of discourse instance').default('h', DISCOURSE_URL).string('h')
.alias('k', 'apikey').describe('k', 'api key from ' + DISCOURSE_URL + '/admin/api').string('k')
.alias('u', 'username').describe('u', 'username to execute operations').default('u', 'system').string('u')
.alias('f', 'dry-run').describe('f', 'don\'t make any changes, just print what would do').boolean('f')
.describe('version', 'prints current version').boolean('boolean')
.argv)
if (argv.version) {
var pkg = require('./package')
console.error(pkg.name, pkg.version)
process.exit(0)
}
var command = argv._[ 0 ]
if (!command) {
optimist.showHelp()
process.exit(1)
}
if (!argv.host || !argv.apikey || !argv.username) {
optimist.showHelp()
console.error('host, apikey and username options are required. They can be specified in a ~/.' + global.CMD_NAME + 'rc file')
process.exit(1)
}
var Discourse = require('discourse-api')
var frm = new Discourse(argv.host, argv.apikey, argv.username)
var commandHandler
try {
commandHandler = require('./cmd/' + command)
} catch (e) {
console.error('Unknown command ' + command)
process.exit(2)
}
require('./lib/helpers')
commandHandler(argv, frm)