11using System . CommandLine ;
22using ChangeTrace . Cli . Interfaces ;
3+ using ChangeTrace . Cli . Prompts ;
34using ChangeTrace . Configuration . Discovery ;
45using ChangeTrace . CredentialTrace . Interfaces ;
56using ChangeTrace . CredentialTrace . Profiles ;
@@ -23,7 +24,8 @@ namespace ChangeTrace.Cli.Handlers.Profiles.Organizations;
2324/// </remarks>
2425[ AutoRegister ( ServiceLifetime . Transient , typeof ( OrgListCommandHandler ) ) ]
2526internal sealed class OrgListCommandHandler (
26- IProfileStore < OrganizationProfile > store ) : ICliHandler
27+ IProfileStore < OrganizationProfile > store ,
28+ IEnumerable < IAuthProvider > providers ) : ICliHandler
2729{
2830 /// <summary>
2931 /// Executes 'org list' command asynchronously.
@@ -35,10 +37,10 @@ public async Task HandleAsync(ParseResult parseResult, CancellationToken ct)
3537 var provider = parseResult . GetValue < string > ( "--provider" ) ;
3638
3739 if ( string . IsNullOrWhiteSpace ( provider ) )
38- {
39- AnsiConsole . MarkupLine ( "[red]Error:[/] --provider is required." ) ;
40+ provider = ProviderPrompt . SelectProvider ( providers ) ;
41+
42+ if ( string . IsNullOrWhiteSpace ( provider ) )
4043 return ;
41- }
4244
4345 try
4446 {
@@ -47,25 +49,15 @@ await AnsiConsole.Status()
4749 . SpinnerStyle ( Style . Parse ( "blue" ) )
4850 . StartAsync ( "Loading organizations..." , async _ =>
4951 {
50- var filtered = ( await store . GetAllAsync ( ct ) )
51- . Where ( o => o . Provider . Equals ( provider , StringComparison . OrdinalIgnoreCase ) )
52- . ToList ( ) ;
52+ var filtered = await GetOrganizationsAsync ( provider , ct ) ;
5353
5454 if ( ! filtered . Any ( ) )
5555 {
5656 AnsiConsole . MarkupLine ( "[yellow]No organizations found.[/]" ) ;
5757 return ;
5858 }
5959
60- var table = new Table { Border = TableBorder . Rounded } ;
61- table . AddColumn ( "Name" ) ;
62- table . AddColumn ( "Provider" ) ;
63-
64- foreach ( var org in filtered )
65- table . AddRow ( org . Name , org . Provider ) ;
66-
67- AnsiConsole . Write ( table ) ;
68-
60+ DisplayOrganizations ( filtered ) ;
6961 DisplayConfirmation ( filtered . Count , provider ) ;
7062 } ) ;
7163 }
@@ -75,6 +67,28 @@ await AnsiConsole.Status()
7567 }
7668 }
7769
70+ /// <summary>
71+ /// Gets organizations matching provider.
72+ /// </summary>
73+ private async Task < List < OrganizationProfile > > GetOrganizationsAsync (
74+ string provider ,
75+ CancellationToken ct ) => [ .. ( await store . GetAllAsync ( ct ) ) . Where ( o => o . Provider . Equals ( provider , StringComparison . OrdinalIgnoreCase ) ) ] ;
76+
77+ /// <summary>
78+ /// Displays organizations table.
79+ /// </summary>
80+ private static void DisplayOrganizations ( IEnumerable < OrganizationProfile > organizations )
81+ {
82+ var table = new Table { Border = TableBorder . Rounded } ;
83+ table . AddColumn ( "Name" ) ;
84+ table . AddColumn ( "Provider" ) ;
85+
86+ foreach ( var org in organizations )
87+ table . AddRow ( org . Name , org . Provider ) ;
88+
89+ AnsiConsole . Write ( table ) ;
90+ }
91+
7892 /// <summary>
7993 /// Displays a confirmation panel with the number of organizations found for a given provider.
8094 /// </summary>
0 commit comments