@@ -4,9 +4,9 @@ Copyright © 2025 Codesphere Inc. <support@codesphere.com>
44package cmd
55
66import (
7- "errors"
87 "fmt"
98
9+ "github.com/codesphere-cloud/cs-go/pkg/api"
1010 "github.com/codesphere-cloud/cs-go/pkg/out"
1111 "github.com/jedib0t/go-pretty/v6/table"
1212
@@ -47,26 +47,50 @@ func (l *ListWorkspacesCmd) parseLogCmdFlags() {
4747}
4848
4949func (l * ListWorkspacesCmd ) RunE (_ * cobra.Command , args []string ) (err error ) {
50- if l .opts .TeamId == nil || * l .opts .TeamId < 0 {
51- return errors .New ("team ID not set or invalid, please use --team-id to set one" )
52- }
53-
5450 client , err := NewClient (l .opts .GlobalOptions )
5551 if err != nil {
5652 return fmt .Errorf ("failed to create Codesphere client: %e" , err )
5753 }
5854
59- workspaces , err := client . ListWorkspaces ( * l . opts . TeamId )
55+ teams , err := l . getTeamIds ( client )
6056 if err != nil {
61- return fmt .Errorf ("failed to list workspaces: %e" , err )
57+ return fmt .Errorf ("failed to get teams: %e" , err )
58+ }
59+ workspaces := []api.Workspace {}
60+ for _ , team := range teams {
61+ teamWorkspaces , err := client .ListWorkspaces (team )
62+ if err != nil {
63+ return fmt .Errorf ("failed to list workspaces: %e" , err )
64+ }
65+ workspaces = append (workspaces , teamWorkspaces ... )
6266 }
6367
6468 t := out .GetTableWriter ()
65- t .AppendHeader (table.Row {"ID" , "Name" , "Repository" })
69+ t .AppendHeader (table.Row {"Team ID" , " ID" , "Name" , "Repository" })
6670 for _ , w := range workspaces {
67- t .AppendRow (table.Row {w .Id , w .Name , * w .GitUrl .Get ()})
71+ gitUrl := ""
72+ if w .GitUrl .Get () != nil {
73+ gitUrl = * w .GitUrl .Get ()
74+ }
75+ t .AppendRow (table.Row {w .TeamId , w .Id , w .Name , gitUrl })
6876 }
6977 t .Render ()
7078
7179 return nil
7280}
81+
82+ func (l * ListWorkspacesCmd ) getTeamIds (client * api.Client ) (teams []int , err error ) {
83+ if l .opts .TeamId != nil && * l .opts .TeamId >= 0 {
84+ teams = append (teams , * l .opts .TeamId )
85+ return
86+ }
87+ var allTeams []api.Team
88+ allTeams , err = client .ListTeams ()
89+ if err != nil {
90+ return
91+ }
92+ for _ , t := range allTeams {
93+ teams = append (teams , int (t .Id ))
94+ }
95+ return
96+ }
0 commit comments