fix(cli): harden providers listing and keep provider map aligned

This commit is contained in:
Chummy 2026-02-18 00:34:23 +08:00
parent feaa4aba60
commit ce23cbaeea
2 changed files with 239 additions and 32 deletions

View file

@ -556,25 +556,37 @@ async fn main() -> Result<()> {
Commands::Providers => {
let providers = providers::list_providers();
let current = config.default_provider.as_deref().unwrap_or("openrouter");
let current = config
.default_provider
.as_deref()
.unwrap_or("openrouter")
.trim()
.to_ascii_lowercase();
println!("Supported providers ({} total):\n", providers.len());
println!(" {:<19} {}", "ID (use in config)", "DESCRIPTION");
println!(" {:<19} {}", "───────────────────", "───────────");
for p in &providers {
let marker = if p.name == current { " (active)" } else { "" };
let is_active = p.name.eq_ignore_ascii_case(&current)
|| p.aliases
.iter()
.any(|alias| alias.eq_ignore_ascii_case(&current));
let marker = if is_active { " (active)" } else { "" };
let local_tag = if p.local { " [local]" } else { "" };
let aliases = if p.aliases.is_empty() {
String::new()
} else {
format!(" (aliases: {})", p.aliases.join(", "))
};
println!(" {:<19} {}{}{}{}", p.name, p.display_name, local_tag, marker, aliases);
println!(
" {:<19} {}{}{}{}",
p.name, p.display_name, local_tag, marker, aliases
);
}
println!("\n custom:<URL> Any OpenAI-compatible endpoint");
println!(" anthropic-custom:<URL> Any Anthropic-compatible endpoint");
Ok(())
}
Commands::Service { service_command } => service::handle_command(&service_command, &config),
Commands::Doctor => doctor::run(&config),