1 | 'use strict'
|
2 |
|
3 | const path = require('path')
|
4 | const PLUGIN_PATH = require('../util/path').PLUGIN_PATH
|
5 | const info = require(path.join(PLUGIN_PATH, 'package.json'))
|
6 | const dependencies = info.dependencies
|
7 |
|
8 | module.exports = function (program) {
|
9 | for (var name in dependencies) {
|
10 | if (/^xdc-(\S+)-command$/.test(name)) {
|
11 | const commandName = name.replace(/^xdc-(\S+)-command$/, '$1')
|
12 | const description = require(path.join(name, 'package.json')).description
|
13 | const action = (_name => () => require(_name)(program))(name)
|
14 | const command = program.command(commandName)
|
15 |
|
16 | command.allowUnknownOption()
|
17 | command.description(description)
|
18 | try {
|
19 | require(path.join(name, 'options'))(command)
|
20 | } catch (_) {
|
21 |
|
22 | }
|
23 | command.action(action)
|
24 | }
|
25 | }
|
26 | }
|