@@ -28,20 +28,25 @@ program
28
28
. option ( '-t, --today' , 'Check the question today.' )
29
29
. option (
30
30
'-i, --identity <identity>' ,
31
- 'Check the specified question by identity.' ,
31
+ 'Check the specified question by identity.'
32
32
)
33
33
. option ( '-r, --random' , 'Check the last random question.' )
34
34
. option ( '-e, --easy' , 'Use easy mode.' )
35
35
. option ( '-d, --directory <directory>' , 'Set the question directory.' )
36
36
. option ( '-l, --language [language]' , 'Set/Get the code language of question.' )
37
37
. option (
38
38
'-u, --update' ,
39
- 'Check the version to determine whether to update to the latest one.' ,
39
+ 'Check the version to determine whether to update to the latest one.'
40
40
)
41
41
. parse ( process . argv )
42
42
43
43
const cmdArgs = program . args
44
44
const cmdOpts = program . opts ( )
45
+ // 获取模式和参数
46
+
47
+ const mode = referMode ( cmdArgs , cmdOpts )
48
+ const args = getArgs ( mode , cmdArgs , cmdOpts )
49
+
45
50
/**
46
51
* 执行逻辑:
47
52
* 目录检测 - 设置基础目录
@@ -56,8 +61,7 @@ const cmdOpts = program.opts()
56
61
if ( cmdOpts . language ) {
57
62
if ( cmdOpts . language !== true ) {
58
63
await easyLanguageView ( cmdOpts . language )
59
- }
60
- else {
64
+ } else {
61
65
const lang = await getQuestionLanguage ( )
62
66
console . log ( `当前CLI语言环境为:${ lang } ` )
63
67
}
@@ -85,14 +89,13 @@ async function check(mode, question) {
85
89
const filePath = path . join (
86
90
baseDir ,
87
91
getQuestionFileName ( question ) ,
88
- `question${ getQuestionFileExtension ( question ?. lang ) } ` ,
92
+ `question${ getQuestionFileExtension ( question ?. lang ) } `
89
93
)
90
94
if ( ! fs . existsSync ( filePath ) ) {
91
95
console . log ( `文件[${ filePath } ]不存在,请确保已经创建!` )
92
- }
93
- else {
96
+ } else {
94
97
console . log (
95
- `MODE: ${ mode } \n题目[${ getQuestionChineseName ( question ) } ]检测结果:` ,
98
+ `MODE: ${ mode } \n题目[${ getQuestionChineseName ( question ) } ]检测结果:`
96
99
)
97
100
await checkQuestion ( filePath )
98
101
}
@@ -116,10 +119,8 @@ const callModeAction = {
116
119
: await getQuestionById ( id )
117
120
await check ( 'identity' , question )
118
121
process . exit ( 0 )
119
- } ,
122
+ }
120
123
}
121
- // 获取模式和参数
122
- const mode = referMode ( cmdArgs , cmdOpts )
123
- const args = getArgs ( mode , cmdArgs , cmdOpts )
124
+
124
125
// 执行指令分发
125
126
callModeAction [ mode ] ( args )
0 commit comments