1 | const cac = require('cac')
|
2 |
|
3 |
|
4 |
|
5 | module.exports = class CLI {
|
6 | constructor(command) {
|
7 | this.command = command
|
8 | this.cac = cac()
|
9 | }
|
10 |
|
11 | handleCommand(...args) {
|
12 | return this.cac.command(...args)
|
13 | }
|
14 |
|
15 | isCurrentCommand(command) {
|
16 | if (command === '*' || command === this.command) return true
|
17 | if (Array.isArray(command) && command.includes(this.command)) return true
|
18 | return false
|
19 | }
|
20 |
|
21 | willShowHelp() {
|
22 | return process.argv.includes('--help')
|
23 | }
|
24 |
|
25 | async runCommand() {
|
26 | const args = [this.command]
|
27 |
|
28 | if (this.willShowHelp()) {
|
29 | args.push('--help')
|
30 | }
|
31 |
|
32 | return this.cac.parse(args)
|
33 | }
|
34 | }
|