Add support for environment file generation in EnvFile struct

- Introduced new methods for writing environment files in YAML and DotEnv formats.
- Updated EnvFile struct to include a buffer for storing key-value pairs.
- Modified write_env_files function to create and write to environment files based on configuration.
- Added tests for environment file writing functionality.
This commit is contained in:
GW_MC
2025-11-25 21:16:21 +08:00
parent d9105957a8
commit f9218e0927
4 changed files with 154 additions and 22 deletions

View File

@@ -29,17 +29,18 @@ pub fn write_env_files(db_config: &DBConfigInfoType) {
DBConfigInfoType::PreExisting(config) => (config.db_type.clone(), config.url.clone()),
};
let api_env_file = EnvFile {
file_type: env::EnvFileType::Yaml,
db_type,
db_url,
};
let mut api_env = EnvFile::new(env::EnvFileType::Yaml, db_type, db_url);
let mut db_env = api_env.clone();
db_env.file_type = env::EnvFileType::DotEnv;
let mut db_env_file = api_env_file.clone();
db_env_file.file_type = env::EnvFileType::DotEnv;
let mut api_file =
std::fs::File::create(&api_config_path_absolute).expect("Failed to create API config file");
api_env_file.write(&api_config_path_absolute);
db_env_file.write(&db_config_path_absolute);
let mut db_file =
std::fs::File::create(&db_config_path_absolute).expect("Failed to create DB config file");
api_env.write(&mut api_file, true);
db_env.write(&mut db_file, false);
}
pub async fn stop_container(