-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·43 lines (35 loc) · 1.18 KB
/
index.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
#!/usr/bin/env node
'use strict'
global.path = require('path');
global.fs = require('fs-extra');
global.log = require('./lib/global-log');
global.VersionStore = require('./lib/version-store');
global.ykitModulesPath = path.join(process.env.HOME, '.ykit_modules');
fs.ensureDirSync(ykitModulesPath);
const program = require('commander');
const commands = {
install: require('./lib/commands/install'),
uninstall: require('./lib/commands/uninstall'),
use: require('./lib/commands/use'),
remote: require('./lib/commands/remote'),
ls: require('./lib/commands/ls')
}
Object.keys(commands).map(name => {
const commandItem = commands[name];
program
.command(commandItem.pattern)
.alias(commandItem.alias)
.description(commandItem.description)
.action(commandItem.action);
})
program
.option('-v, --version', 'check ykit-cli version')
.parse(process.argv);
// 没有任何命令和参数
if(process.argv[2] === '-v' || process.argv[2] === '--version') {
console.log(require('./package.json').version);
}
// 没有任何命令和参数
if(process.argv.length === 2) {
console.log('program', process.argv.length ,program.help());
}