Skip to content

Commit e7fde8c

Browse files
author
Lasim
committed
feat(gateway): update team switching command to use team number
1 parent 5f59c5e commit e7fde8c

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

services/gateway/src/commands/teams.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +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')
13+
.option('--switch <team-number>', 'Switch to a different team by team number (#)')
1414
.action(async (options) => {
1515
const storage = new CredentialStorage();
1616
let backendUrl = 'https://cloud.deploystack.io'; // Default fallback
@@ -39,20 +39,19 @@ export function registerTeamsCommand(program: Command) {
3939

4040
// Handle team switching
4141
if (options.switch) {
42-
const teamToSwitch = teams.find(team =>
43-
team.name.toLowerCase() === options.switch.toLowerCase() ||
44-
team.slug.toLowerCase() === options.switch.toLowerCase()
45-
);
42+
const teamNumber = parseInt(options.switch, 10);
4643

47-
if (!teamToSwitch) {
48-
console.log(chalk.red(`❌ Team "${options.switch}" not found`));
44+
if (isNaN(teamNumber) || teamNumber < 1 || teamNumber > teams.length) {
45+
console.log(chalk.red(`❌ Invalid team number "${options.switch}". Please use a number between 1 and ${teams.length}`));
4946
console.log(chalk.gray('Available teams:'));
50-
teams.forEach(team => console.log(chalk.gray(` - ${team.name}`)));
47+
teams.forEach((team, index) => console.log(chalk.gray(` ${index + 1}. ${team.name} (ID: ${team.id})`)));
5148
process.exit(1);
5249
}
5350

51+
const teamToSwitch = teams[teamNumber - 1]; // Convert to 0-based index
52+
5453
await storage.updateSelectedTeam(teamToSwitch.id, teamToSwitch.name);
55-
console.log(chalk.green(`✅ Switched to team: ${chalk.cyan(teamToSwitch.name)}`));
54+
console.log(chalk.green(`✅ Switched to team: ${chalk.cyan(teamToSwitch.name)} (#${teamNumber})`));
5655
console.log(chalk.gray(`🌐 Using backend: ${backendUrl}`));
5756
return;
5857
}
@@ -71,18 +70,18 @@ export function registerTeamsCommand(program: Command) {
7170
if (selectedTeam) {
7271
console.log(chalk.gray(`🎯 Currently selected: ${chalk.cyan(selectedTeam.name)}`));
7372
} else {
74-
console.log(chalk.yellow('⚠️ No team selected - use --switch <team-name> to select one'));
73+
console.log(chalk.yellow('⚠️ No team selected - use --switch <team-number> to select one'));
7574
}
7675

7776
console.log(chalk.gray(`🌐 Using backend: ${backendUrl}\n`));
7877

7978
// Create table
8079
const table = TableFormatter.createTable({
81-
head: ['Team Name', 'Role', 'Ownership', 'Default', 'Selected'],
82-
colWidths: [25, 18, 15, 10, 10]
80+
head: ['#', 'Team Name', 'Role', 'Ownership', 'Default', 'Selected'],
81+
colWidths: [3, 20, 16, 12, 10, 10]
8382
});
8483

85-
teams.forEach(team => {
84+
teams.forEach((team, index) => {
8685
// Format role with colors and descriptions
8786
let roleDisplay: string;
8887
if (team.role === 'team_admin') {
@@ -95,14 +94,15 @@ export function registerTeamsCommand(program: Command) {
9594
const ownershipDisplay = team.is_owner ? chalk.green('✅ Owner') : chalk.gray('👤 Member');
9695

9796
// Format default team status
98-
const defaultDisplay = team.is_default ? chalk.yellow('Default') : chalk.gray('Regular');
97+
const defaultDisplay = team.is_default ? chalk.yellow('Default') : chalk.gray('Regular');
9998

10099
// Format selected team status
101100
const isSelected = selectedTeam && selectedTeam.id === team.id;
102-
const selectedDisplay = isSelected ? chalk.green('Active') : chalk.gray('Inactive');
101+
const selectedDisplay = isSelected ? chalk.green('Active') : chalk.gray('Inactive');
103102

104103
table.push([
105-
TableFormatter.truncate(team.name, 23),
104+
chalk.cyan((index + 1).toString()),
105+
TableFormatter.truncate(team.name, 18),
106106
roleDisplay,
107107
ownershipDisplay,
108108
defaultDisplay,
@@ -114,7 +114,7 @@ export function registerTeamsCommand(program: Command) {
114114

115115
// Show helpful tips
116116
console.log();
117-
console.log(chalk.gray(`💡 Use 'deploystack teams --switch <team-name>' to switch to a different team`));
117+
console.log(chalk.gray(`💡 Use 'deploystack teams --switch <team-number>' to switch to a different team`));
118118

119119
// Show ownership summary
120120
const ownedTeams = teams.filter(team => team.is_owner);

0 commit comments

Comments
 (0)