hubot 10.0.1 → 10.0.3
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.js +4 -4
- package/package.json +1 -2
- package/src/OptParse.js +44 -0
package/bin/hubot.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
const fs = require('fs')
|
|
4
4
|
const pathResolve = require('path').resolve
|
|
5
5
|
|
|
6
|
-
const OptParse = require('
|
|
6
|
+
const OptParse = require('../src/OptParse.js')
|
|
7
7
|
|
|
8
8
|
const Hubot = require('..')
|
|
9
9
|
const create = require('../src/GenHubot.js')
|
|
@@ -32,8 +32,8 @@ const options = {
|
|
|
32
32
|
configCheck: false
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
const Parser = new OptParse
|
|
36
|
-
Parser.banner = 'Usage hubot [options]'
|
|
35
|
+
const Parser = new OptParse(switches)
|
|
36
|
+
Parser.banner = 'Usage: hubot [options]'
|
|
37
37
|
|
|
38
38
|
Parser.on('adapter', (opt, value) => {
|
|
39
39
|
options.adapter = value
|
|
@@ -80,7 +80,7 @@ Parser.on('version', (opt, value) => {
|
|
|
80
80
|
options.version = true
|
|
81
81
|
})
|
|
82
82
|
|
|
83
|
-
Parser.on((opt, value) => {
|
|
83
|
+
Parser.on(undefined, (opt, value) => {
|
|
84
84
|
console.warn(`Unknown option: ${opt}`)
|
|
85
85
|
})
|
|
86
86
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hubot",
|
|
3
|
-
"version": "10.0.
|
|
3
|
+
"version": "10.0.3",
|
|
4
4
|
"author": "hubot",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"github",
|
|
@@ -19,7 +19,6 @@
|
|
|
19
19
|
"connect-multiparty": "^2.2.0",
|
|
20
20
|
"express": "^4.18.2",
|
|
21
21
|
"express-basic-auth": "^1.2.1",
|
|
22
|
-
"optparse": "^1.0.5",
|
|
23
22
|
"pino": "^8.11.0"
|
|
24
23
|
},
|
|
25
24
|
"devDependencies": {
|
package/src/OptParse.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
const EventEmitter = require('node:events')
|
|
2
|
+
class OptParse extends EventEmitter {
|
|
3
|
+
constructor (switches) {
|
|
4
|
+
super()
|
|
5
|
+
this.switches = switches
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
mappings (switches) {
|
|
9
|
+
const mappings = switches.reduce((acc, current) => {
|
|
10
|
+
acc[current[0].replace('-', '')] = current[1].split(' ')[0].replace('--', '')
|
|
11
|
+
return acc
|
|
12
|
+
}, {})
|
|
13
|
+
return mappings
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
parse (args) {
|
|
17
|
+
const mappings = this.mappings(this.switches)
|
|
18
|
+
const options = {}
|
|
19
|
+
for (let i = 0; i < args.length; i++) {
|
|
20
|
+
const arg = args[i]
|
|
21
|
+
if (arg.startsWith('-')) {
|
|
22
|
+
let key = arg.replace(/^-+/, '')
|
|
23
|
+
key = mappings[key] || key
|
|
24
|
+
key = key.replace(/-([a-z])/g, g => g[1].toUpperCase())
|
|
25
|
+
const nextArg = args[i + 1]
|
|
26
|
+
if (nextArg && !nextArg.startsWith('-')) {
|
|
27
|
+
options[key] = nextArg
|
|
28
|
+
i++
|
|
29
|
+
} else {
|
|
30
|
+
options[key] = true
|
|
31
|
+
}
|
|
32
|
+
this.emit(key, key, nextArg)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return options
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
toString () {
|
|
39
|
+
return `${this.banner}
|
|
40
|
+
${this.switches.map(([key, description]) => ` ${key}, ${description}`).join('\n')}`
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
module.exports = OptParse
|