@@ -10,15 +10,10 @@ import {
10
10
import { ACTIVATION , gitUserOptions } from "@/shared/config" ;
11
11
import { GitUserOptions } from ".." ;
12
12
13
- async function printCurrentGitUser ( isBefore : boolean = true ) {
14
- printInfo ( `${ isBefore ? "当前" : "最新" } 使用的 Git UserName :` ) ;
15
- await execCommand ( "git" , [ "config" , "user.name" ] , {
16
- stdio : "inherit" ,
17
- } ) ;
18
- printInfo ( `${ isBefore ? "当前" : "最新" } 使用的 Git UserEmail :` ) ;
19
- await execCommand ( "git" , [ "config" , "user.email" ] , {
20
- stdio : "inherit" ,
21
- } ) ;
13
+ async function printCurrentGitUser ( ) {
14
+ const name = await execCommand ( "git" , [ "config" , "user.name" ] ) ;
15
+ const email = await execCommand ( "git" , [ "config" , "user.email" ] ) ;
16
+ printInfo ( `\ngit config info:\n user.name: ${ name } \n user.email: ${ email } ` ) ;
22
17
}
23
18
24
19
export const gitUser = async ( options : GitUserOptions ) => {
@@ -31,46 +26,41 @@ export const gitUser = async (options: GitUserOptions) => {
31
26
const nameRegExp = new RegExp ( ruleName ! ) ;
32
27
const emailRegExp = new RegExp ( ruleEmail ! , "i" ) ;
33
28
34
- await printCurrentGitUser ( true ) ;
29
+ await printCurrentGitUser ( ) ;
35
30
36
31
if ( name ) {
37
32
if ( ! nameRegExp . test ( name ) ) {
38
- printWarring ( `因输入的 ${ name } 不符合 name 规则, 未能成功设置 name ` ) ;
33
+ printWarring ( `设置失败(user.name), ${ name } 不符合规范 ` ) ;
39
34
} else {
40
35
await execCommand ( "git" , [ "config" , "user.name" , name ] , {
41
36
stdio : "inherit" ,
42
37
} ) ;
43
- printInfo ( `最新使用的 Git UserName :` ) ;
44
- await execCommand ( "git" , [ "config" , "user.name" ] , {
45
- stdio : "inherit" ,
46
- } ) ;
38
+ const result = await execCommand ( "git" , [ "config" , "user.name" ] ) ;
39
+ printInfo ( `更新成功(user.name): ${ result } ` ) ;
47
40
}
48
41
}
49
42
50
43
if ( email ) {
51
44
if ( ! emailRegExp . test ( email ) ) {
52
- printWarring ( `因输入的 ${ email } 不符合 email 规则, 未能成功设置 email ` ) ;
45
+ printWarring ( `设置失败(user.email), ${ email } 不符合规范 ` ) ;
53
46
} else {
54
47
await execCommand ( "git" , [ "config" , "user.email" , email ] , {
55
48
stdio : "inherit" ,
56
49
} ) ;
57
- printInfo ( `最新使用的 Git UserEmail :` ) ;
58
- await execCommand ( "git" , [ "config" , "user.email" ] , {
59
- stdio : "inherit" ,
60
- } ) ;
50
+ const result = await execCommand ( "git" , [ "config" , "user.email" ] ) ;
51
+ printInfo ( `更新成功(user.email): ${ result } ` ) ;
61
52
}
62
53
}
63
54
64
55
if ( ! name && ! email ) {
65
56
const username = await execCommand ( "git" , [ "config" , "user.name" ] ) ;
66
57
if ( ! nameRegExp . test ( username ) ) {
67
- printError ( "Git 配置的 user.name 不符合规范, 请更换" ) ;
58
+ printError ( ` ${ username } 不符合 ${ ruleName } 规范` ) ;
68
59
process . exit ( 1 ) ;
69
60
}
70
-
71
61
const useremail = await execCommand ( "git" , [ "config" , "user.email" ] ) ;
72
62
if ( ! emailRegExp . test ( useremail ) ) {
73
- printError ( "Git 配置的 user.email 不符合规范, 请更换" ) ;
63
+ printError ( ` ${ useremail } 不符合 ${ ruleEmail } 规范` ) ;
74
64
process . exit ( 1 ) ;
75
65
}
76
66
}
@@ -94,10 +84,7 @@ export default function gitUserInstaller(cli: CAC) {
94
84
default : gitUserOptions . ruleEmail ,
95
85
} ,
96
86
)
97
- . action ( async ( options ) => {
98
- console . log ( options ) ;
99
- await gitUser ( options ) ;
100
- } ) ;
87
+ . action ( async ( options ) => await gitUser ( options ) ) ;
101
88
} ,
102
89
} ;
103
90
}
0 commit comments