@@ -10,6 +10,7 @@ export function registerTeamsCommand(program: Command) {
1010 . command ( 'teams' )
1111 . description ( 'List your teams and team information' )
1212 . option ( '--url <url>' , 'DeployStack backend URL (override stored URL)' )
13+ . option ( '--switch <team-name>' , 'Switch to a different team' )
1314 . action ( async ( options ) => {
1415 const storage = new CredentialStorage ( ) ;
1516 let backendUrl = 'https://cloud.deploystack.io' ; // Default fallback
@@ -33,49 +34,112 @@ export function registerTeamsCommand(program: Command) {
3334 backendUrl = options . url || credentials . baseUrl || 'https://cloud.deploystack.io' ;
3435 const api = new DeployStackAPI ( credentials , backendUrl ) ;
3536
36- // Get teams
37+ // Get fresh teams data from the API (real-time verification)
3738 const teams = await api . getUserTeams ( ) ;
39+
40+ // Handle team switching
41+ if ( options . switch ) {
42+ const teamToSwitch = teams . find ( team =>
43+ team . name . toLowerCase ( ) === options . switch . toLowerCase ( ) ||
44+ team . slug . toLowerCase ( ) === options . switch . toLowerCase ( )
45+ ) ;
46+
47+ if ( ! teamToSwitch ) {
48+ console . log ( chalk . red ( `❌ Team "${ options . switch } " not found` ) ) ;
49+ console . log ( chalk . gray ( 'Available teams:' ) ) ;
50+ teams . forEach ( team => console . log ( chalk . gray ( ` - ${ team . name } ` ) ) ) ;
51+ process . exit ( 1 ) ;
52+ }
53+
54+ await storage . updateSelectedTeam ( teamToSwitch . id , teamToSwitch . name ) ;
55+ console . log ( chalk . green ( `✅ Switched to team: ${ chalk . cyan ( teamToSwitch . name ) } ` ) ) ;
56+ console . log ( chalk . gray ( `🌐 Using backend: ${ backendUrl } ` ) ) ;
57+ return ;
58+ }
3859
3960 if ( teams . length === 0 ) {
4061 console . log ( chalk . yellow ( '📭 You are not a member of any teams' ) ) ;
4162 console . log ( chalk . gray ( '💡 Contact your administrator to be added to a team' ) ) ;
63+ console . log ( chalk . gray ( `🌐 Using backend: ${ backendUrl } ` ) ) ;
4264 return ;
4365 }
4466
45- console . log ( chalk . blue ( `👥 Your Teams (${ teams . length } team${ teams . length === 1 ? '' : 's' } found)\n` ) ) ;
67+ console . log ( chalk . blue ( `👥 Your Teams (${ teams . length } team${ teams . length === 1 ? '' : 's' } found)` ) ) ;
68+
69+ // Show currently selected team
70+ const selectedTeam = await storage . getSelectedTeam ( ) ;
71+ if ( selectedTeam ) {
72+ console . log ( chalk . gray ( `🎯 Currently selected: ${ chalk . cyan ( selectedTeam . name ) } ` ) ) ;
73+ } else {
74+ console . log ( chalk . yellow ( '⚠️ No team selected - use --switch <team-name> to select one' ) ) ;
75+ }
76+
77+ console . log ( chalk . gray ( `🌐 Using backend: ${ backendUrl } \n` ) ) ;
4678
4779 // Create table
4880 const table = TableFormatter . createTable ( {
49- head : [ 'Team Name' , 'Role' , 'Members ' , 'Default' , 'Created ' ] ,
50- colWidths : [ 25 , 15 , 8 , 7 , 12 ]
81+ head : [ 'Team Name' , 'Role' , 'Ownership ' , 'Default' , 'Selected ' ] ,
82+ colWidths : [ 25 , 18 , 15 , 10 , 10 ]
5183 } ) ;
5284
5385 teams . forEach ( team => {
86+ // Format role with colors and descriptions
87+ let roleDisplay : string ;
88+ if ( team . role === 'team_admin' ) {
89+ roleDisplay = team . is_owner ? chalk . green ( 'Owner/Admin' ) : chalk . cyan ( 'Admin' ) ;
90+ } else {
91+ roleDisplay = chalk . gray ( 'User' ) ;
92+ }
93+
94+ // Format ownership status
95+ const ownershipDisplay = team . is_owner ? chalk . green ( '✅ Owner' ) : chalk . gray ( '👤 Member' ) ;
96+
97+ // Format default team status
98+ const defaultDisplay = team . is_default ? chalk . yellow ( '✅ Default' ) : chalk . gray ( 'Regular' ) ;
99+
100+ // Format selected team status
101+ const isSelected = selectedTeam && selectedTeam . id === team . id ;
102+ const selectedDisplay = isSelected ? chalk . green ( '✅ Active' ) : chalk . gray ( 'Inactive' ) ;
103+
54104 table . push ( [
55105 TableFormatter . truncate ( team . name , 23 ) ,
56- team . role === 'team_admin' ? chalk . cyan ( 'admin' ) : chalk . gray ( 'user' ) ,
57- team . member_count . toString ( ) ,
58- TableFormatter . formatBoolean ( team . is_default ) ,
59- TableFormatter . formatDate ( team . created_at )
106+ roleDisplay ,
107+ ownershipDisplay ,
108+ defaultDisplay ,
109+ selectedDisplay
60110 ] ) ;
61111 } ) ;
62112
63113 console . log ( table . toString ( ) ) ;
64114
65115 // Show helpful tips
66116 console . log ( ) ;
67- console . log ( chalk . gray ( `💡 Use 'deploystack start --team <team-name>' to start gateway for specific team` ) ) ;
117+ console . log ( chalk . gray ( `💡 Use 'deploystack teams --switch <team-name>' to switch to a different team` ) ) ;
68118
69- // Show default team info
119+ // Show ownership summary
120+ const ownedTeams = teams . filter ( team => team . is_owner ) ;
121+ const adminTeams = teams . filter ( team => team . role === 'team_admin' && ! team . is_owner ) ;
122+ const userTeams = teams . filter ( team => team . role === 'team_user' ) ;
70123 const defaultTeam = teams . find ( team => team . is_default ) ;
124+
125+ if ( ownedTeams . length > 0 ) {
126+ console . log ( chalk . gray ( `💡 You own ${ ownedTeams . length } team${ ownedTeams . length === 1 ? '' : 's' } : ${ ownedTeams . map ( t => chalk . cyan ( t . name ) ) . join ( ', ' ) } ` ) ) ;
127+ }
128+ if ( adminTeams . length > 0 ) {
129+ console . log ( chalk . gray ( `💡 You have admin access to ${ adminTeams . length } additional team${ adminTeams . length === 1 ? '' : 's' } ` ) ) ;
130+ }
131+ if ( userTeams . length > 0 ) {
132+ console . log ( chalk . gray ( `💡 You have user access to ${ userTeams . length } team${ userTeams . length === 1 ? '' : 's' } ` ) ) ;
133+ }
71134 if ( defaultTeam ) {
72135 console . log ( chalk . gray ( `💡 Your default team is: ${ chalk . cyan ( defaultTeam . name ) } ` ) ) ;
73136 }
74-
75- // Show admin teams
76- const adminTeams = teams . filter ( team => team . role === 'team_admin' ) ;
77- if ( adminTeams . length > 0 ) {
78- console . log ( chalk . gray ( `💡 You have admin access to ${ adminTeams . length } team${ adminTeams . length === 1 ? '' : 's' } ` ) ) ;
137+
138+ // Show member count if available
139+ const teamsWithMemberCount = teams . filter ( team => team . member_count !== undefined ) ;
140+ if ( teamsWithMemberCount . length > 0 ) {
141+ const totalMembers = teamsWithMemberCount . reduce ( ( sum , team ) => sum + ( team . member_count || 0 ) , 0 ) ;
142+ console . log ( chalk . gray ( `📊 Total team members across all teams: ${ totalMembers } ` ) ) ;
79143 }
80144
81145 } catch ( error ) {
0 commit comments