Skip to content

Commit 5641d4c

Browse files
authored
fix(hubot): hubot --help wasn't working (#1693)
1 parent 5738ea1 commit 5641d4c

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

bin/hubot.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const options = {
3333
}
3434

3535
const Parser = new OptParse(switches)
36-
Parser.banner = 'Usage hubot [options]'
36+
Parser.banner = 'Usage: hubot [options]'
3737

3838
Parser.on('adapter', (opt, value) => {
3939
options.adapter = value

src/OptParse.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ class OptParse extends EventEmitter {
3434
}
3535
return options
3636
}
37+
38+
toString () {
39+
return `${this.banner}
40+
${this.switches.map(([key, description]) => ` ${key}, ${description}`).join('\n')}`
41+
}
3742
}
3843

3944
module.exports = OptParse

test/hubot_test.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const { TextMessage, User } = require('../index.js')
99
const path = require('node:path')
1010

1111
describe('Running bin/hubot.js', () => {
12-
it('should load adapter from HUBOT_FILE environment variable', async function () {
12+
it('should load adapter from HUBOT_FILE environment variable', async () => {
1313
process.env.HUBOT_HTTPD = 'false'
1414
process.env.HUBOT_FILE = path.resolve(root, 'test', 'fixtures', 'MockAdapter.mjs')
1515
const hubot = require('../bin/hubot.js')
@@ -31,4 +31,32 @@ describe('Running bin/hubot.js', () => {
3131
hubot.shutdown()
3232
}
3333
})
34+
const { spawn } = require('child_process')
35+
36+
it('should output a help message when run with --help', (t, done) => {
37+
const hubot = spawn('./bin/hubot', ['--help'])
38+
const expected = `Usage: hubot [options]
39+
-a, --adapter HUBOT_ADAPTER
40+
-f, --file HUBOT_FILE
41+
-c, --create HUBOT_CREATE
42+
-d, --disable-httpd HUBOT_HTTPD
43+
-h, --help
44+
-l, --alias HUBOT_ALIAS
45+
-n, --name HUBOT_NAME
46+
-r, --require PATH
47+
-t, --config-check
48+
-v, --version
49+
`
50+
let actual = ''
51+
hubot.stdout.on('data', (data) => {
52+
actual += data.toString()
53+
})
54+
hubot.stderr.on('data', (data) => {
55+
actual += data.toString()
56+
})
57+
hubot.on('close', (code) => {
58+
assert.deepEqual(actual, expected)
59+
done()
60+
})
61+
})
3462
})

0 commit comments

Comments
 (0)