@@ -10,15 +10,10 @@ import {
1010import { ACTIVATION , gitUserOptions } from "@/shared/config" ;
1111import { GitUserOptions } from ".." ;
1212
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 } ` ) ;
2217}
2318
2419export const gitUser = async ( options : GitUserOptions ) => {
@@ -31,46 +26,41 @@ export const gitUser = async (options: GitUserOptions) => {
3126 const nameRegExp = new RegExp ( ruleName ! ) ;
3227 const emailRegExp = new RegExp ( ruleEmail ! , "i" ) ;
3328
34- await printCurrentGitUser ( true ) ;
29+ await printCurrentGitUser ( ) ;
3530
3631 if ( name ) {
3732 if ( ! nameRegExp . test ( name ) ) {
38- printWarring ( `因输入的 ${ name } 不符合 name 规则, 未能成功设置 name ` ) ;
33+ printWarring ( `设置失败(user.name), ${ name } 不符合规范 ` ) ;
3934 } else {
4035 await execCommand ( "git" , [ "config" , "user.name" , name ] , {
4136 stdio : "inherit" ,
4237 } ) ;
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 } ` ) ;
4740 }
4841 }
4942
5043 if ( email ) {
5144 if ( ! emailRegExp . test ( email ) ) {
52- printWarring ( `因输入的 ${ email } 不符合 email 规则, 未能成功设置 email ` ) ;
45+ printWarring ( `设置失败(user.email), ${ email } 不符合规范 ` ) ;
5346 } else {
5447 await execCommand ( "git" , [ "config" , "user.email" , email ] , {
5548 stdio : "inherit" ,
5649 } ) ;
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 } ` ) ;
6152 }
6253 }
6354
6455 if ( ! name && ! email ) {
6556 const username = await execCommand ( "git" , [ "config" , "user.name" ] ) ;
6657 if ( ! nameRegExp . test ( username ) ) {
67- printError ( "Git 配置的 user.name 不符合规范, 请更换" ) ;
58+ printError ( ` ${ username } 不符合 ${ ruleName } 规范` ) ;
6859 process . exit ( 1 ) ;
6960 }
70-
7161 const useremail = await execCommand ( "git" , [ "config" , "user.email" ] ) ;
7262 if ( ! emailRegExp . test ( useremail ) ) {
73- printError ( "Git 配置的 user.email 不符合规范, 请更换" ) ;
63+ printError ( ` ${ useremail } 不符合 ${ ruleEmail } 规范` ) ;
7464 process . exit ( 1 ) ;
7565 }
7666 }
@@ -94,10 +84,7 @@ export default function gitUserInstaller(cli: CAC) {
9484 default : gitUserOptions . ruleEmail ,
9585 } ,
9686 )
97- . action ( async ( options ) => {
98- console . log ( options ) ;
99- await gitUser ( options ) ;
100- } ) ;
87+ . action ( async ( options ) => await gitUser ( options ) ) ;
10188 } ,
10289 } ;
10390}
0 commit comments