1
1
import { Command } from 'commander'
2
2
3
+ export interface VipCommanderDetailOptions {
4
+ command : string
5
+ aliases : string [ ]
6
+ summary : string
7
+ description : string
8
+ }
9
+
10
+ export interface VipCommanderOptions {
11
+ dryRun ?: boolean
12
+ trace ?: boolean
13
+ vip ?: boolean
14
+ help ?: boolean
15
+ }
3
16
/**
4
17
* 终端交互
5
18
* 参考:https://www.npmjs.com/package/commander
@@ -8,15 +21,57 @@ export class VipCommander extends Command {
8
21
constructor ( name : string , version : string , description ?: string ) {
9
22
super ( name )
10
23
// 查看版本
11
- this . version ( version , '-v --version' , 'VipCommander Version By @142vip' )
24
+ this . version ( version , '-v, --version' , 'VipCommander Version By @142vip' )
12
25
13
26
// 添加描述
14
27
if ( description != null ) {
15
28
this . description ( description )
16
29
}
17
30
31
+ /**
32
+ * 增加默认的一些参数
33
+ */
34
+ // this
35
+ // .option('--dry-run', '试运行', false)
36
+ // .option('--vip', '@142vip组织专用功能', false)
37
+ // .option('--logger', '开启日志追踪模式', false)
38
+
39
+ // 对命令增加help方法
40
+ // this.helpCommand(true)
41
+ }
42
+
43
+ /**
44
+ * 对命令初始化,增加aliases,summary,description等信息
45
+ */
46
+ public initCommand ( options : VipCommanderDetailOptions , {
47
+ dryRun = true ,
48
+ trace = true ,
49
+ vip = false ,
50
+ help = false ,
51
+ } : VipCommanderOptions ) : VipCommander {
52
+ const vipCommander = this . command ( options . command , options . description )
53
+ . aliases ( options . aliases )
54
+ . summary ( options . summary )
55
+ . description ( options . description )
56
+
57
+ if ( trace ) {
58
+ vipCommander . option ( '--trace' , '开启日志追踪模式' , false )
59
+ }
60
+
61
+ if ( dryRun ) {
62
+ vipCommander . option ( '--dry-run' , '试运行' , false )
63
+ }
64
+
65
+ if ( vip ) {
66
+ vipCommander . option ( '--vip' , '@142vip组织专用功能' , false )
67
+ }
68
+
18
69
// 对命令增加help方法
19
- this . helpCommand ( true )
70
+ if ( help ) {
71
+ vipCommander . helpCommand ( true )
72
+ }
73
+
74
+ return vipCommander
20
75
}
21
76
22
77
// 对description、summary方法重新,增加颜色处理
0 commit comments