style: fix clippy uninlined_format_args warnings

Apply clippy --fix to use inline format arguments in:
- src/mcp.rs (8 fixes)
- src/services/env_manager.rs (10 fixes)
This commit is contained in:
YoVinchen
2025-11-19 01:13:22 +08:00
parent f582bd58b1
commit bbb356a948
2 changed files with 27 additions and 21 deletions

View File

@@ -536,7 +536,7 @@ pub fn import_from_codex(config: &mut MultiAppConfig) -> Result<usize, AppError>
if !json_arr.is_empty() { if !json_arr.is_empty() {
Some(serde_json::Value::Array(json_arr)) Some(serde_json::Value::Array(json_arr))
} else { } else {
log::debug!("跳过复杂数组字段 '{}' (TOML → JSON)", key); log::debug!("跳过复杂数组字段 '{key}' (TOML → JSON)");
None None
} }
} }
@@ -551,19 +551,19 @@ pub fn import_from_codex(config: &mut MultiAppConfig) -> Result<usize, AppError>
if !json_obj.is_empty() { if !json_obj.is_empty() {
Some(serde_json::Value::Object(json_obj)) Some(serde_json::Value::Object(json_obj))
} else { } else {
log::debug!("跳过复杂对象字段 '{}' (TOML → JSON)", key); log::debug!("跳过复杂对象字段 '{key}' (TOML → JSON)");
None None
} }
} }
toml::Value::Datetime(_) => { toml::Value::Datetime(_) => {
log::debug!("跳过日期时间字段 '{}' (TOML → JSON)", key); log::debug!("跳过日期时间字段 '{key}' (TOML → JSON)");
None None
} }
}; };
if let Some(val) = json_val { if let Some(val) = json_val {
spec.insert(key.clone(), val); spec.insert(key.clone(), val);
log::debug!("导入扩展字段 '{}' = {:?}", key, toml_val); log::debug!("导入扩展字段 '{key}' = {toml_val:?}");
} }
} }
@@ -831,7 +831,7 @@ fn json_value_to_toml_item(value: &Value, field_name: &str) -> Option<toml_edit:
} else if let Some(f) = n.as_f64() { } else if let Some(f) = n.as_f64() {
Some(toml_edit::value(f)) Some(toml_edit::value(f))
} else { } else {
log::warn!("跳过字段 '{field_name}': 无法转换的数字类型 {}", n); log::warn!("跳过字段 '{field_name}': 无法转换的数字类型 {n}");
None None
} }
} }
@@ -1009,9 +1009,9 @@ fn json_server_to_toml_table(spec: &Value) -> Result<toml_edit::Table, AppError>
// 记录扩展字段的处理 // 记录扩展字段的处理
if extended_fields.contains(&key.as_str()) { if extended_fields.contains(&key.as_str()) {
log::debug!("已转换扩展字段 '{}' = {:?}", key, value); log::debug!("已转换扩展字段 '{key}' = {value:?}");
} else { } else {
log::info!("已转换自定义字段 '{}' = {:?}", key, value); log::info!("已转换自定义字段 '{key}' = {value:?}");
} }
} }
} }
@@ -1094,7 +1094,7 @@ pub fn remove_server_from_codex(id: &str) -> Result<(), AppError> {
if let Some(mcp_table) = doc.get_mut("mcp").and_then(|t| t.as_table_mut()) { if let Some(mcp_table) = doc.get_mut("mcp").and_then(|t| t.as_table_mut()) {
if let Some(servers) = mcp_table.get_mut("servers").and_then(|s| s.as_table_mut()) { if let Some(servers) = mcp_table.get_mut("servers").and_then(|s| s.as_table_mut()) {
if servers.remove(id).is_some() { if servers.remove(id).is_some() {
log::warn!("从错误的 MCP 格式 [mcp.servers] 中清理了服务器 '{}'", id); log::warn!("从错误的 MCP 格式 [mcp.servers] 中清理了服务器 '{id}'");
} }
} }
} }

View File

@@ -43,11 +43,11 @@ pub fn delete_env_vars(conflicts: Vec<EnvConflict>) -> Result<BackupInfo, String
fn create_backup(conflicts: &[EnvConflict]) -> Result<BackupInfo, String> { fn create_backup(conflicts: &[EnvConflict]) -> Result<BackupInfo, String> {
// Get backup directory // Get backup directory
let backup_dir = get_backup_dir()?; let backup_dir = get_backup_dir()?;
fs::create_dir_all(&backup_dir).map_err(|e| format!("创建备份目录失败: {}", e))?; fs::create_dir_all(&backup_dir).map_err(|e| format!("创建备份目录失败: {e}"))?;
// Generate backup file name with timestamp // Generate backup file name with timestamp
let timestamp = Utc::now().format("%Y%m%d_%H%M%S").to_string(); let timestamp = Utc::now().format("%Y%m%d_%H%M%S").to_string();
let backup_file = backup_dir.join(format!("env-backup-{}.json", timestamp)); let backup_file = backup_dir.join(format!("env-backup-{timestamp}.json"));
// Create backup data // Create backup data
let backup_info = BackupInfo { let backup_info = BackupInfo {
@@ -58,9 +58,9 @@ fn create_backup(conflicts: &[EnvConflict]) -> Result<BackupInfo, String> {
// Write backup file // Write backup file
let json = serde_json::to_string_pretty(&backup_info) let json = serde_json::to_string_pretty(&backup_info)
.map_err(|e| format!("序列化备份数据失败: {}", e))?; .map_err(|e| format!("序列化备份数据失败: {e}"))?;
fs::write(&backup_file, json).map_err(|e| format!("写入备份文件失败: {}", e))?; fs::write(&backup_file, json).map_err(|e| format!("写入备份文件失败: {e}"))?;
Ok(backup_info) Ok(backup_info)
} }
@@ -115,7 +115,7 @@ fn delete_single_env(conflict: &EnvConflict) -> Result<(), String> {
// Read file content // Read file content
let content = fs::read_to_string(file_path) let content = fs::read_to_string(file_path)
.map_err(|e| format!("读取文件失败 {}: {}", file_path, e))?; .map_err(|e| format!("读取文件失败 {file_path}: {e}"))?;
// Filter out the line containing the environment variable // Filter out the line containing the environment variable
let new_content: Vec<String> = content let new_content: Vec<String> = content
@@ -137,7 +137,7 @@ fn delete_single_env(conflict: &EnvConflict) -> Result<(), String> {
// Write back to file // Write back to file
fs::write(file_path, new_content.join("\n")) fs::write(file_path, new_content.join("\n"))
.map_err(|e| format!("写入文件失败 {}: {}", file_path, e))?; .map_err(|e| format!("写入文件失败 {file_path}: {e}"))?;
Ok(()) Ok(())
} }
@@ -153,10 +153,10 @@ fn delete_single_env(conflict: &EnvConflict) -> Result<(), String> {
pub fn restore_from_backup(backup_path: String) -> Result<(), String> { pub fn restore_from_backup(backup_path: String) -> Result<(), String> {
// Read backup file // Read backup file
let content = let content =
fs::read_to_string(&backup_path).map_err(|e| format!("读取备份文件失败: {}", e))?; fs::read_to_string(&backup_path).map_err(|e| format!("读取备份文件失败: {e}"))?;
let backup_info: BackupInfo = serde_json::from_str(&content) let backup_info: BackupInfo =
.map_err(|e| format!("解析备份文件失败: {}", e))?; serde_json::from_str(&content).map_err(|e| format!("解析备份文件失败: {e}"))?;
// Restore each variable // Restore each variable
for conflict in &backup_info.conflicts { for conflict in &backup_info.conflicts {
@@ -190,7 +190,10 @@ fn restore_single_env(conflict: &EnvConflict) -> Result<(), String> {
} }
Ok(()) Ok(())
} }
_ => Err(format!("无法恢复类型为 {} 的环境变量", conflict.source_type)), _ => Err(format!(
"无法恢复类型为 {} 的环境变量",
conflict.source_type
)),
} }
} }
@@ -208,7 +211,7 @@ fn restore_single_env(conflict: &EnvConflict) -> Result<(), String> {
// Read file content // Read file content
let mut content = fs::read_to_string(file_path) let mut content = fs::read_to_string(file_path)
.map_err(|e| format!("读取文件失败 {}: {}", file_path, e))?; .map_err(|e| format!("读取文件失败 {file_path}: {e}"))?;
// Append the environment variable line // Append the environment variable line
let export_line = format!("\nexport {}={}", conflict.var_name, conflict.var_value); let export_line = format!("\nexport {}={}", conflict.var_name, conflict.var_value);
@@ -216,11 +219,14 @@ fn restore_single_env(conflict: &EnvConflict) -> Result<(), String> {
// Write back to file // Write back to file
fs::write(file_path, content) fs::write(file_path, content)
.map_err(|e| format!("写入文件失败 {}: {}", file_path, e))?; .map_err(|e| format!("写入文件失败 {file_path}: {e}"))?;
Ok(()) Ok(())
} }
_ => Err(format!("无法恢复类型为 {} 的环境变量", conflict.source_type)), _ => Err(format!(
"无法恢复类型为 {} 的环境变量",
conflict.source_type
)),
} }
} }