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:
@@ -536,7 +536,7 @@ pub fn import_from_codex(config: &mut MultiAppConfig) -> Result<usize, AppError>
|
||||
if !json_arr.is_empty() {
|
||||
Some(serde_json::Value::Array(json_arr))
|
||||
} else {
|
||||
log::debug!("跳过复杂数组字段 '{}' (TOML → JSON)", key);
|
||||
log::debug!("跳过复杂数组字段 '{key}' (TOML → JSON)");
|
||||
None
|
||||
}
|
||||
}
|
||||
@@ -551,19 +551,19 @@ pub fn import_from_codex(config: &mut MultiAppConfig) -> Result<usize, AppError>
|
||||
if !json_obj.is_empty() {
|
||||
Some(serde_json::Value::Object(json_obj))
|
||||
} else {
|
||||
log::debug!("跳过复杂对象字段 '{}' (TOML → JSON)", key);
|
||||
log::debug!("跳过复杂对象字段 '{key}' (TOML → JSON)");
|
||||
None
|
||||
}
|
||||
}
|
||||
toml::Value::Datetime(_) => {
|
||||
log::debug!("跳过日期时间字段 '{}' (TOML → JSON)", key);
|
||||
log::debug!("跳过日期时间字段 '{key}' (TOML → JSON)");
|
||||
None
|
||||
}
|
||||
};
|
||||
|
||||
if let Some(val) = json_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() {
|
||||
Some(toml_edit::value(f))
|
||||
} else {
|
||||
log::warn!("跳过字段 '{field_name}': 无法转换的数字类型 {}", n);
|
||||
log::warn!("跳过字段 '{field_name}': 无法转换的数字类型 {n}");
|
||||
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()) {
|
||||
log::debug!("已转换扩展字段 '{}' = {:?}", key, value);
|
||||
log::debug!("已转换扩展字段 '{key}' = {value:?}");
|
||||
} 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(servers) = mcp_table.get_mut("servers").and_then(|s| s.as_table_mut()) {
|
||||
if servers.remove(id).is_some() {
|
||||
log::warn!("从错误的 MCP 格式 [mcp.servers] 中清理了服务器 '{}'", id);
|
||||
log::warn!("从错误的 MCP 格式 [mcp.servers] 中清理了服务器 '{id}'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,11 +43,11 @@ pub fn delete_env_vars(conflicts: Vec<EnvConflict>) -> Result<BackupInfo, String
|
||||
fn create_backup(conflicts: &[EnvConflict]) -> Result<BackupInfo, String> {
|
||||
// Get backup directory
|
||||
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
|
||||
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
|
||||
let backup_info = BackupInfo {
|
||||
@@ -58,9 +58,9 @@ fn create_backup(conflicts: &[EnvConflict]) -> Result<BackupInfo, String> {
|
||||
|
||||
// Write backup file
|
||||
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)
|
||||
}
|
||||
@@ -115,7 +115,7 @@ fn delete_single_env(conflict: &EnvConflict) -> Result<(), String> {
|
||||
|
||||
// Read file content
|
||||
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
|
||||
let new_content: Vec<String> = content
|
||||
@@ -137,7 +137,7 @@ fn delete_single_env(conflict: &EnvConflict) -> Result<(), String> {
|
||||
|
||||
// Write back to file
|
||||
fs::write(file_path, new_content.join("\n"))
|
||||
.map_err(|e| format!("写入文件失败 {}: {}", file_path, e))?;
|
||||
.map_err(|e| format!("写入文件失败 {file_path}: {e}"))?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -153,10 +153,10 @@ fn delete_single_env(conflict: &EnvConflict) -> Result<(), String> {
|
||||
pub fn restore_from_backup(backup_path: String) -> Result<(), String> {
|
||||
// Read backup file
|
||||
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)
|
||||
.map_err(|e| format!("解析备份文件失败: {}", e))?;
|
||||
let backup_info: BackupInfo =
|
||||
serde_json::from_str(&content).map_err(|e| format!("解析备份文件失败: {e}"))?;
|
||||
|
||||
// Restore each variable
|
||||
for conflict in &backup_info.conflicts {
|
||||
@@ -190,7 +190,10 @@ fn restore_single_env(conflict: &EnvConflict) -> Result<(), String> {
|
||||
}
|
||||
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
|
||||
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
|
||||
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
|
||||
fs::write(file_path, content)
|
||||
.map_err(|e| format!("写入文件失败 {}: {}", file_path, e))?;
|
||||
.map_err(|e| format!("写入文件失败 {file_path}: {e}"))?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
_ => Err(format!("无法恢复类型为 {} 的环境变量", conflict.source_type)),
|
||||
_ => Err(format!(
|
||||
"无法恢复类型为 {} 的环境变量",
|
||||
conflict.source_type
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user