From 45fa18bc84c06a6dfa37cc7d1770d8a2dc93861a Mon Sep 17 00:00:00 2001 From: Fankai Liu Date: Sat, 28 Oct 2023 23:02:51 +0800 Subject: [PATCH] Optimized code --- src/utils/create_project.rs | 62 ++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 29 deletions(-) diff --git a/src/utils/create_project.rs b/src/utils/create_project.rs index 29064a2..cb9a436 100644 --- a/src/utils/create_project.rs +++ b/src/utils/create_project.rs @@ -37,42 +37,46 @@ pub fn create_project(project: Project) -> Result<()> { init_git(project_path)?; - success(t!("create_success", project_name = project_name).replace(r"\n", "\n")); - match config.db_conn_type { - DbConnectionType::Sqlx => { - success( - t!("create_success_sqlx", project_name = project_name).replace(r"\n", "\n"), - ); - } - DbConnectionType::SeaOrm => { - success( - t!("create_success_sea_orm", project_name = project_name).replace(r"\n", "\n"), - ); + after_print_info(project_name, config); + } + None => anyhow::bail!("cli quit!"), + } + Ok(()) +} + +fn after_print_info(project_name: &String, config: UserSelected) { + success(t!("create_success", project_name = project_name).replace(r"\n", "\n")); + match config.db_conn_type { + DbConnectionType::Sqlx => { + success( + t!("create_success_sqlx", project_name = project_name).replace(r"\n", "\n"), + ); + } + DbConnectionType::SeaOrm => { + success( + t!("create_success_sea_orm", project_name = project_name).replace(r"\n", "\n"), + ); + } + DbConnectionType::Diesel => { + match config.db_type { + DbType::Sqlite => { + success(t!("create_success_sqlx_sqlite").replace(r"\n", "\n")); } - DbConnectionType::Diesel => { - match config.db_type { - DbType::Sqlite => { - success(t!("create_success_sqlx_sqlite").replace(r"\n", "\n")); - } - _ => { - success(t!("create_success_mysql_or_pgsql").replace(r"\n", "\n")); - } - } + _ => { + success(t!("create_success_mysql_or_pgsql").replace(r"\n", "\n")); } - DbConnectionType::Rbatis => { - match config.db_type { - DbType::Mysql | DbType::Postgres | DbType::Mssql => { - success(t!("create_success_rbatis")); - } - _ => {} - } + } + } + DbConnectionType::Rbatis => { + match config.db_type { + DbType::Mysql | DbType::Postgres | DbType::Mssql => { + success(t!("create_success_rbatis")); } _ => {} } } - None => anyhow::bail!("cli quit!"), + _ => {} } - Ok(()) } fn write_project_file(