hubot 11.2.2 → 11.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/Hubot.mjs +13 -3
- package/package.json +1 -1
- package/src/OptParse.mjs +10 -6
package/bin/Hubot.mjs
CHANGED
|
@@ -16,7 +16,8 @@ const switches = [
|
|
|
16
16
|
['-n', '--name HUBOT_NAME', 'The name of the robot in chat'],
|
|
17
17
|
['-r', '--require PATH', 'Alternative scripts path'],
|
|
18
18
|
['-t', '--config-check', "Test hubot's config to make sure it won't fail at startup"],
|
|
19
|
-
['-v', '--version', 'Displays the version of hubot installed']
|
|
19
|
+
['-v', '--version', 'Displays the version of hubot installed'],
|
|
20
|
+
['-e', '--execute', 'Runs the command as if it were a hubot command']
|
|
20
21
|
]
|
|
21
22
|
|
|
22
23
|
const options = {
|
|
@@ -66,6 +67,10 @@ Parser.on('name', (opt, value) => {
|
|
|
66
67
|
options.name = value
|
|
67
68
|
})
|
|
68
69
|
|
|
70
|
+
Parser.on('execute', (opt, value) => {
|
|
71
|
+
options.execute = value
|
|
72
|
+
})
|
|
73
|
+
|
|
69
74
|
Parser.on('require', (opt, value) => {
|
|
70
75
|
options.scripts.push(value)
|
|
71
76
|
})
|
|
@@ -141,7 +146,12 @@ async function loadExternalScripts () {
|
|
|
141
146
|
process.exit(0)
|
|
142
147
|
}
|
|
143
148
|
|
|
144
|
-
robot.adapter.once('connected',
|
|
145
|
-
|
|
149
|
+
robot.adapter.once('connected', async () => {
|
|
150
|
+
await loadScripts()
|
|
151
|
+
if (options.execute) {
|
|
152
|
+
await robot.receive(new Hubot.TextMessage(new Hubot.User('shell', { room: '#shell' }), `@${robot.name} ${options.execute.trim()}`))
|
|
153
|
+
robot.shutdown()
|
|
154
|
+
}
|
|
155
|
+
})
|
|
146
156
|
await robot.run()
|
|
147
157
|
})()
|
package/package.json
CHANGED
package/src/OptParse.mjs
CHANGED
|
@@ -19,17 +19,21 @@ class OptParse extends EventEmitter {
|
|
|
19
19
|
for (let i = 0; i < args.length; i++) {
|
|
20
20
|
const arg = args[i]
|
|
21
21
|
if (arg.startsWith('-')) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
const cliArg = arg.replace(/^-+/, '')
|
|
23
|
+
let propertyName = mappings[cliArg]
|
|
24
|
+
if (!propertyName) {
|
|
25
|
+
propertyName = Object.values(mappings).find(value => value === cliArg)
|
|
26
|
+
}
|
|
27
|
+
const nameToEmit = propertyName
|
|
28
|
+
propertyName = propertyName.replace(/-([a-z])/g, g => g[1].toUpperCase())
|
|
25
29
|
const nextArg = args[i + 1]
|
|
26
30
|
if (nextArg && !nextArg.startsWith('-')) {
|
|
27
|
-
options[
|
|
31
|
+
options[propertyName] = nextArg
|
|
28
32
|
i++
|
|
29
33
|
} else {
|
|
30
|
-
options[
|
|
34
|
+
options[propertyName] = true
|
|
31
35
|
}
|
|
32
|
-
this.emit(
|
|
36
|
+
this.emit(nameToEmit, propertyName, nextArg)
|
|
33
37
|
}
|
|
34
38
|
}
|
|
35
39
|
return options
|