@@ -117,6 +117,7 @@ type listResult struct {
117
117
type DetailProject struct {
118
118
FullName string
119
119
Project * apiv1.Project
120
+ Err error
120
121
}
121
122
122
123
func 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
190
191
return projects , warnings , nil
191
192
}
192
193
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
+ }
196
210
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 ) {
198
215
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
201
221
c , err := Client (ctx , opts )
202
222
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
204
226
}
205
227
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 ,
211
230
Project : project ,
231
+ Err : err ,
212
232
}
213
233
}(projectName , opts )
214
234
}
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
226
235
}
0 commit comments