refactor(providers): add flexible app type resolution with dual parameter support
Add `resolve_app_type` helper to support both enum and string-based app type parameters across all provider commands. This change: - Eliminates implicit default to Claude (previously used `unwrap_or`) - Supports two parameter forms: `app_type` (enum, priority 1) and `app` (string, priority 2) - Provides explicit error handling when both parameters are missing - Updates all 14 provider command functions with consistent parameter validation - Fixes tray menu provider switching to pass the new `app` parameter This dual-parameter approach maintains backward compatibility while enabling future CLI tool integration and more flexible API usage patterns. Technical details: - Priority order: `app_type` enum > `app` string > error - Invalid `app` strings now return errors instead of defaulting - All existing tests pass (45/45)
This commit is contained in:
@@ -267,7 +267,12 @@ fn switch_provider_internal(
|
||||
let app_type_str = app_type.as_str().to_string();
|
||||
let provider_id_clone = provider_id.clone();
|
||||
|
||||
crate::commands::switch_provider(app_state.clone(), Some(app_type), provider_id)
|
||||
crate::commands::switch_provider(
|
||||
app_state.clone(),
|
||||
Some(app_type),
|
||||
Some(app_type_str.clone()),
|
||||
provider_id,
|
||||
)
|
||||
.map_err(AppError::Message)?;
|
||||
|
||||
// 切换成功后重新创建托盘菜单
|
||||
|
||||
Reference in New Issue
Block a user