@@ -117,6 +117,7 @@ type listResult struct {
117117type DetailProject struct {
118118 FullName string
119119 Project * apiv1.Project
120+ Err error
120121}
121122
122123func listHubServers (ctx context.Context , wg * sync.WaitGroup , creds * credentials.Store , cfg * config.CLIConfig , result chan <- listResult ) {
@@ -190,37 +191,45 @@ func List(ctx context.Context, opts Options) (projects []string, warnings map[st
190191 return projects , warnings , nil
191192}
192193
193- func GetDetails (ctx context.Context , opts Options , projectNames []string ) (result []DetailProject , err error ) {
194- entryCh := make (chan DetailProject )
195- errCh := make (chan error )
194+ func GetDetails (ctx context.Context , opts Options , projectNames []string ) (projects []DetailProject ) {
195+ var (
196+ wg sync.WaitGroup
197+ result = make (chan DetailProject )
198+ )
199+
200+ getProjectDetails (ctx , & wg , result , opts , projectNames )
201+
202+ go func () {
203+ wg .Wait ()
204+ close (result )
205+ }()
206+
207+ for detailProject := range result {
208+ projects = append (projects , detailProject )
209+ }
196210
197- // Launch a goroutine for each project to retrieve its information
211+ return projects
212+ }
213+
214+ func getProjectDetails (ctx context.Context , wg * sync.WaitGroup , result chan <- DetailProject , opts Options , projectNames []string ) {
198215 for _ , projectName := range projectNames {
199- go func (proj string , opts Options ) {
200- opts .Project = proj
216+ wg .Add (1 )
217+ go func (projectName string , opts Options ) {
218+ defer wg .Done ()
219+ // Launch a goroutine for each project to retrieve its information
220+ opts .Project = projectName
201221 c , err := Client (ctx , opts )
202222 if err != nil {
203- errCh <- err
223+ logrus .Warnf ("unable to get client for %s: %s" , projectName , err )
224+ // just ignore invalid clients
225+ return
204226 }
205227 project , err := c .ProjectGet (ctx , lastPart (opts .Project ))
206- if err != nil {
207- errCh <- err
208- }
209- entryCh <- DetailProject {
210- FullName : proj ,
228+ result <- DetailProject {
229+ FullName : projectName ,
211230 Project : project ,
231+ Err : err ,
212232 }
213233 }(projectName , opts )
214234 }
215-
216- for i := 0 ; i < len (projectNames ); i ++ {
217- select {
218- case entry := <- entryCh :
219- result = append (result , entry )
220- case err := <- errCh :
221- return nil , err
222- }
223- }
224-
225- return result , nil
226235}
0 commit comments