diff --git a/bin/hubot.js b/bin/hubot.js index 6b42721b7..2f7ab841f 100755 --- a/bin/hubot.js +++ b/bin/hubot.js @@ -33,7 +33,7 @@ const options = { } const Parser = new OptParse(switches) -Parser.banner = 'Usage hubot [options]' +Parser.banner = 'Usage: hubot [options]' Parser.on('adapter', (opt, value) => { options.adapter = value diff --git a/src/OptParse.js b/src/OptParse.js index f5b2add1a..6344150b6 100644 --- a/src/OptParse.js +++ b/src/OptParse.js @@ -34,6 +34,11 @@ class OptParse extends EventEmitter { } return options } + + toString () { + return `${this.banner} +${this.switches.map(([key, description]) => ` ${key}, ${description}`).join('\n')}` + } } module.exports = OptParse diff --git a/test/hubot_test.js b/test/hubot_test.js index 8b83646a8..479b23c0e 100644 --- a/test/hubot_test.js +++ b/test/hubot_test.js @@ -9,7 +9,7 @@ const { TextMessage, User } = require('../index.js') const path = require('node:path') describe('Running bin/hubot.js', () => { - it('should load adapter from HUBOT_FILE environment variable', async function () { + it('should load adapter from HUBOT_FILE environment variable', async () => { process.env.HUBOT_HTTPD = 'false' process.env.HUBOT_FILE = path.resolve(root, 'test', 'fixtures', 'MockAdapter.mjs') const hubot = require('../bin/hubot.js') @@ -31,4 +31,32 @@ describe('Running bin/hubot.js', () => { hubot.shutdown() } }) + const { spawn } = require('child_process') + + it('should output a help message when run with --help', (t, done) => { + const hubot = spawn('./bin/hubot', ['--help']) + const expected = `Usage: hubot [options] + -a, --adapter HUBOT_ADAPTER + -f, --file HUBOT_FILE + -c, --create HUBOT_CREATE + -d, --disable-httpd HUBOT_HTTPD + -h, --help + -l, --alias HUBOT_ALIAS + -n, --name HUBOT_NAME + -r, --require PATH + -t, --config-check + -v, --version +` + let actual = '' + hubot.stdout.on('data', (data) => { + actual += data.toString() + }) + hubot.stderr.on('data', (data) => { + actual += data.toString() + }) + hubot.on('close', (code) => { + assert.deepEqual(actual, expected) + done() + }) + }) })