Skip to content

Commit 9ba2435

Browse files
amitksingh1490autofix-ci[bot]tusharmath
authored
fix(zsh): filter provider list to show only llm providers (#2098)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Tushar Mathur <tusharmath@gmail.com>
1 parent 8345b26 commit 9ba2435

5 files changed

Lines changed: 45 additions & 14 deletions

File tree

crates/forge_domain/src/provider.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ use std::collections::HashMap;
44
use derive_more::{AsRef, Deref, From};
55
use schemars::JsonSchema;
66
use serde::{Deserialize, Serialize};
7-
use strum_macros::Display;
7+
use strum_macros::{Display, EnumString};
88
use url::Url;
99

1010
use crate::{ApiKey, AuthCredential, AuthDetails, Model, Template};
1111

1212
/// Distinguishes between different categories of providers
13-
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Display, Default)]
13+
#[derive(
14+
Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Display, EnumString, Default,
15+
)]
1416
#[serde(rename_all = "snake_case")]
1517
#[strum(serialize_all = "snake_case")]
1618
pub enum ProviderType {

crates/forge_main/src/cli.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,12 @@ pub enum ListCommand {
281281

282282
/// List available API providers.
283283
#[command(alias = "providers")]
284-
Provider,
284+
Provider {
285+
/// Filter providers by type (e.g., llm, context_engine). Can be
286+
/// specified multiple times.
287+
#[arg(long = "type", short = 't')]
288+
types: Vec<forge_domain::ProviderType>,
289+
},
285290

286291
/// List available models.
287292
#[command(alias = "models")]
@@ -574,7 +579,12 @@ pub enum ProviderCommand {
574579
},
575580

576581
/// List available providers.
577-
List,
582+
List {
583+
/// Filter providers by type (e.g., llm, context_engine). Can be
584+
/// specified multiple times.
585+
#[arg(long = "type", short = 't')]
586+
types: Vec<forge_domain::ProviderType>,
587+
},
578588
}
579589

580590
/// Group of Commit-related commands

crates/forge_main/src/ui.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -383,8 +383,8 @@ impl<A: API + 'static, F: Fn() -> A + Send + Sync> UI<A, F> {
383383
ListCommand::Agent => {
384384
self.on_show_agents(porcelain).await?;
385385
}
386-
ListCommand::Provider => {
387-
self.on_show_providers(porcelain).await?;
386+
ListCommand::Provider { types } => {
387+
self.on_show_providers(porcelain, types).await?;
388388
}
389389
ListCommand::Model => {
390390
self.on_show_models(porcelain).await?;
@@ -756,8 +756,9 @@ impl<A: API + 'static, F: Fn() -> A + Send + Sync> UI<A, F> {
756756
ProviderCommand::Logout { provider } => {
757757
self.handle_provider_logout(provider.as_ref()).await?;
758758
}
759-
ProviderCommand::List => {
760-
self.on_show_providers(provider_group.porcelain).await?;
759+
ProviderCommand::List { types } => {
760+
self.on_show_providers(provider_group.porcelain, types)
761+
.await?;
761762
}
762763
}
763764

@@ -977,8 +978,17 @@ impl<A: API + 'static, F: Fn() -> A + Send + Sync> UI<A, F> {
977978
}
978979

979980
/// Lists all the providers
980-
async fn on_show_providers(&mut self, porcelain: bool) -> anyhow::Result<()> {
981-
let providers = self.api.get_providers().await?;
981+
async fn on_show_providers(
982+
&mut self,
983+
porcelain: bool,
984+
types: Vec<forge_domain::ProviderType>,
985+
) -> anyhow::Result<()> {
986+
let mut providers = self.api.get_providers().await?;
987+
988+
// Filter by type if specified
989+
if !types.is_empty() {
990+
providers.retain(|p| types.contains(p.provider_type()));
991+
}
982992

983993
if providers.is_empty() {
984994
return Ok(());

shell-plugin/lib/actions/config.zsh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,12 @@ function _forge_action_agent() {
8080
function _forge_action_provider() {
8181
echo
8282
local selected
83-
selected=$(_forge_select_provider)
83+
# Only show LLM providers (exclude context_engine and other non-LLM types)
84+
selected=$(_forge_select_provider "" "" "llm")
8485

8586
if [[ -n "$selected" ]]; then
8687
# Extract the second field (provider ID) from the selected line
87-
# Format: "DisplayName provider_id host status"
88+
# Format: "DisplayName provider_id host type status"
8889
local provider_id=$(echo "$selected" | awk '{print $2}')
8990
# Always use config set - it will handle authentication if needed
9091
_forge_exec config set provider "$provider_id"

shell-plugin/lib/actions/provider.zsh

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,21 @@
33
# Provider selection helper
44

55
# Helper function to select a provider from the list
6-
# Usage: _forge_select_provider [filter_status] [current_provider]
6+
# Usage: _forge_select_provider [filter_status] [current_provider] [filter_type]
77
# Returns: selected provider line (via stdout)
88
function _forge_select_provider() {
99
local filter_status="${1:-}"
1010
local current_provider="${2:-}"
11+
local filter_type="${3:-}"
1112
local output
12-
output=$($_FORGE_BIN list provider --porcelain 2>/dev/null)
13+
14+
# Build the command with type filter if specified
15+
local cmd="$_FORGE_BIN list provider --porcelain"
16+
if [[ -n "$filter_type" ]]; then
17+
cmd="$cmd --type=$filter_type"
18+
fi
19+
20+
output=$(eval "$cmd" 2>/dev/null)
1321

1422
if [[ -z "$output" ]]; then
1523
_forge_log error "No providers available"

0 commit comments

Comments
 (0)