-
Notifications
You must be signed in to change notification settings - Fork 1
/
oclif-setup.js
43 lines (37 loc) · 1.31 KB
/
oclif-setup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const {Hook, Config, Command} = require('@oclif/config')
const {CLIError, error, exit, warn} = require('@oclif/errors')
const Debug = require('@oclif/config/lib/debug').default
const debug = Debug();
const findCommand = Config.prototype.findCommand;
const runCommand = Config.prototype.runCommand;
async function runCommandEx( id, argv = []) {
debug('runCommand %s %o', id, argv)
let c = this.findCommand(id)
if (!c) {
c = this.findCommand('default')
argv.unshift(id)
}
if (!c) {
await this.runHook('command_not_found', {id})
throw new CLIError(`command ${id} not found`)
}
const command = c.load()
await this.runHook('prerun', {Command: command, argv})
const result = await command.run(argv, this)
await this.runHook('postrun', {Command: command, result: result, argv})
}
function findCommandEx( id, opts = {}) {
console.log('TCL::: findCommandEx -> id', id, this);
const must = opts.must;
if (must) opts.must = false;
let result = findCommand.apply(this, arguments );
if (!result) {
if (must) opts.must = true;
result = findCommand.call(this, 'download', opts)
if (result) result.prototype.realId = id;
}
console.log('TCL::: findCommandEx -> result', !!result);
return result;
}
// Config.prototype.findCommand = findCommandEx;
Config.prototype.runCommand = runCommandEx;