@@ -30,39 +30,39 @@ program
30
30
31
31
const cmdArgs = program . args ;
32
32
const cmdOpts = program . opts ( ) ;
33
+ // 创建
34
+ const create = ( mode , question ) => {
35
+ return new Promise ( resolve => {
36
+ setQuestion ( mode , question ) ;
37
+ const questionDir = path . join ( process . cwd ( ) , getQuestionFileName ( question ) )
38
+ createQuestion ( question , questionDir ) . then ( async ( path ) => {
39
+ if ( ! path ) path = await createQuestionCopy ( question , questionDir ) ;
40
+ console . log ( `[lc] 获取随机题目成功\n题目为[${ question . title } ]\n文件地址为:${ path } ` )
41
+ resolve ( true )
42
+ } )
43
+ } )
44
+ }
33
45
// 模式对应的action
34
46
const callModeAction = {
35
47
'today' : ( ) => {
36
48
getQuestionToday ( ) . then ( question => {
37
- setQuestion ( "today" , question ) ;
38
- const questionDir = path . join ( process . cwd ( ) , getQuestionFileName ( question ) )
39
- createQuestion ( question , questionDir ) . then ( async ( path ) => {
40
- if ( ! path ) path = await createQuestionCopy ( question , questionDir ) ;
41
- console . log ( `[lc] 获取今日题目成功\n题目为[${ question . title } ]\n文件地址为:${ path } ` )
42
- process . exit ( 0 ) ;
43
- } )
49
+ create ( "today" , question ) . then ( ( ) => {
50
+ process . exit ( 0 )
51
+ } ) ;
44
52
} )
45
53
} ,
46
54
'random' : ( ) => {
47
55
getQuestionRandom ( ) . then ( question => {
48
- setQuestion ( "random" , question ) ;
49
- const questionDir = path . join ( process . cwd ( ) , getQuestionFileName ( question ) )
50
- createQuestion ( question , questionDir ) . then ( async ( path ) => {
51
- if ( ! path ) path = await createQuestionCopy ( question , questionDir ) ;
52
- console . log ( `[lc] 获取随机题目成功\n题目为[${ question . title } ]\n文件地址为:${ path } ` )
53
- process . exit ( 0 ) ;
54
- } )
56
+ create ( "random" , question ) . then ( ( ) => {
57
+ process . exit ( 0 )
58
+ } ) ;
55
59
} )
56
60
} ,
57
61
'identity' : ( id ) => {
58
62
getQuestionById ( id ) . then ( question => {
59
- setQuestion ( "identity" , question ) ;
60
- const questionDir = path . join ( process . cwd ( ) , getQuestionFileName ( question ) )
61
- createQuestion ( question , questionDir ) . then ( async ( path ) => {
62
- if ( ! path ) path = await createQuestionCopy ( question , questionDir ) ;
63
- console . log ( `[lc] 获取指定题目成功\n题目为[${ question . title } ]\n文件地址为:${ path } ` )
64
- process . exit ( 0 ) ;
65
- } )
63
+ create ( "identity" , question ) . then ( ( ) => {
64
+ process . exit ( 0 )
65
+ } ) ;
66
66
} )
67
67
} ,
68
68
}
@@ -71,4 +71,3 @@ const mode = referMode(cmdArgs, cmdOpts);
71
71
const args = getArgs ( mode , cmdArgs , cmdOpts ) ;
72
72
// 执行指令分发
73
73
await callModeAction [ mode ] ( args ) ;
74
- //
0 commit comments