@@ -29,6 +29,7 @@ import (
29
29
"github.com/cortexlabs/cortex/pkg/lib/json"
30
30
"github.com/cortexlabs/cortex/pkg/lib/msgpack"
31
31
"github.com/cortexlabs/cortex/pkg/lib/sets/strset"
32
+ "github.com/cortexlabs/cortex/pkg/lib/slices"
32
33
s "github.com/cortexlabs/cortex/pkg/lib/strings"
33
34
libtime "github.com/cortexlabs/cortex/pkg/lib/time"
34
35
"github.com/cortexlabs/cortex/pkg/lib/urls"
@@ -153,19 +154,19 @@ func resourceByNameStr(resourceName string, resourcesRes *schema.GetResourcesRes
153
154
func resourcesByTypeStr (resourceType resource.Type , resourcesRes * schema.GetResourcesResponse ) (string , error ) {
154
155
switch resourceType {
155
156
case resource .PythonPackageType :
156
- return " \n " + pythonPackagesStr (resourcesRes .DataStatuses , resourcesRes .Context ), nil
157
+ return pythonPackagesStr (resourcesRes .DataStatuses , resourcesRes .Context , false ), nil
157
158
case resource .RawColumnType :
158
- return " \n " + rawColumnsStr (resourcesRes .DataStatuses , resourcesRes .Context ), nil
159
+ return rawColumnsStr (resourcesRes .DataStatuses , resourcesRes .Context , false ), nil
159
160
case resource .AggregateType :
160
- return " \n " + aggregatesStr (resourcesRes .DataStatuses , resourcesRes .Context ), nil
161
+ return aggregatesStr (resourcesRes .DataStatuses , resourcesRes .Context , false ), nil
161
162
case resource .TransformedColumnType :
162
- return " \n " + transformedColumnsStr (resourcesRes .DataStatuses , resourcesRes .Context ), nil
163
+ return transformedColumnsStr (resourcesRes .DataStatuses , resourcesRes .Context , false ), nil
163
164
case resource .TrainingDatasetType :
164
- return " \n " + trainingDataStr (resourcesRes .DataStatuses , resourcesRes .Context ), nil
165
+ return trainingDataStr (resourcesRes .DataStatuses , resourcesRes .Context , false ), nil
165
166
case resource .ModelType :
166
- return " \n " + modelsStr (resourcesRes .DataStatuses , resourcesRes .Context ), nil
167
+ return modelsStr (resourcesRes .DataStatuses , resourcesRes .Context , false ), nil
167
168
case resource .APIType :
168
- return " \n " + apisStr (resourcesRes .APIGroupStatuses ), nil
169
+ return apisStr (resourcesRes .APIGroupStatuses , false ), nil
169
170
default :
170
171
return "" , resource .ErrorInvalidType (resourceType .String ())
171
172
}
@@ -193,18 +194,29 @@ func resourceByNameAndTypeStr(resourceName string, resourceType resource.Type, r
193
194
}
194
195
195
196
func allResourcesStr (resourcesRes * schema.GetResourcesResponse ) string {
197
+ ctx := resourcesRes .Context
198
+
199
+ showTitle := false
200
+ if slices .AreNGreaterThanZero (2 ,
201
+ len (ctx .PythonPackages ), len (ctx .RawColumns ), len (ctx .Aggregates ),
202
+ len (ctx .TransformedColumns ), len (ctx .Models ), len (ctx .Models ), // Models occurs twice because of training datasets
203
+ len (resourcesRes .APIGroupStatuses ),
204
+ ) {
205
+ showTitle = true
206
+ }
207
+
196
208
out := ""
197
- out += pythonPackagesStr (resourcesRes .DataStatuses , resourcesRes . Context )
198
- out += rawColumnsStr (resourcesRes .DataStatuses , resourcesRes . Context )
199
- out += aggregatesStr (resourcesRes .DataStatuses , resourcesRes . Context )
200
- out += transformedColumnsStr (resourcesRes .DataStatuses , resourcesRes . Context )
201
- out += trainingDataStr (resourcesRes .DataStatuses , resourcesRes . Context )
202
- out += modelsStr (resourcesRes .DataStatuses , resourcesRes . Context )
203
- out += apisStr (resourcesRes .APIGroupStatuses )
209
+ out += pythonPackagesStr (resourcesRes .DataStatuses , ctx , showTitle )
210
+ out += rawColumnsStr (resourcesRes .DataStatuses , ctx , showTitle )
211
+ out += aggregatesStr (resourcesRes .DataStatuses , ctx , showTitle )
212
+ out += transformedColumnsStr (resourcesRes .DataStatuses , ctx , showTitle )
213
+ out += trainingDataStr (resourcesRes .DataStatuses , ctx , showTitle )
214
+ out += modelsStr (resourcesRes .DataStatuses , ctx , showTitle )
215
+ out += apisStr (resourcesRes .APIGroupStatuses , showTitle )
204
216
return out
205
217
}
206
218
207
- func pythonPackagesStr (dataStatuses map [string ]* resource.DataStatus , ctx * context.Context ) string {
219
+ func pythonPackagesStr (dataStatuses map [string ]* resource.DataStatus , ctx * context.Context , showTitle bool ) string {
208
220
if len (ctx .PythonPackages ) == 0 {
209
221
return ""
210
222
}
@@ -213,10 +225,15 @@ func pythonPackagesStr(dataStatuses map[string]*resource.DataStatus, ctx *contex
213
225
for name , pythonPackage := range ctx .PythonPackages {
214
226
strings [name ] = dataResourceRow (name , pythonPackage , dataStatuses )
215
227
}
216
- return titleStr ("Python Packages" ) + dataResourcesHeader () + strMapToStr (strings )
228
+
229
+ title := "\n "
230
+ if showTitle {
231
+ title = titleStr ("Python Packages" )
232
+ }
233
+ return title + dataResourcesHeader () + strMapToStr (strings )
217
234
}
218
235
219
- func rawColumnsStr (dataStatuses map [string ]* resource.DataStatus , ctx * context.Context ) string {
236
+ func rawColumnsStr (dataStatuses map [string ]* resource.DataStatus , ctx * context.Context , showTitle bool ) string {
220
237
if len (ctx .RawColumns ) == 0 {
221
238
return ""
222
239
}
@@ -225,10 +242,15 @@ func rawColumnsStr(dataStatuses map[string]*resource.DataStatus, ctx *context.Co
225
242
for name , rawColumn := range ctx .RawColumns {
226
243
strings [name ] = dataResourceRow (name , rawColumn , dataStatuses )
227
244
}
228
- return titleStr ("Raw Columns" ) + dataResourcesHeader () + strMapToStr (strings )
245
+
246
+ title := "\n "
247
+ if showTitle {
248
+ title = titleStr ("Raw Columns" )
249
+ }
250
+ return title + dataResourcesHeader () + strMapToStr (strings )
229
251
}
230
252
231
- func aggregatesStr (dataStatuses map [string ]* resource.DataStatus , ctx * context.Context ) string {
253
+ func aggregatesStr (dataStatuses map [string ]* resource.DataStatus , ctx * context.Context , showTitle bool ) string {
232
254
if len (ctx .Aggregates ) == 0 {
233
255
return ""
234
256
}
@@ -237,10 +259,15 @@ func aggregatesStr(dataStatuses map[string]*resource.DataStatus, ctx *context.Co
237
259
for name , aggregate := range ctx .Aggregates {
238
260
strings [name ] = dataResourceRow (name , aggregate , dataStatuses )
239
261
}
240
- return titleStr ("Aggregates" ) + dataResourcesHeader () + strMapToStr (strings )
262
+
263
+ title := "\n "
264
+ if showTitle {
265
+ title = titleStr ("Aggregates" )
266
+ }
267
+ return title + dataResourcesHeader () + strMapToStr (strings )
241
268
}
242
269
243
- func transformedColumnsStr (dataStatuses map [string ]* resource.DataStatus , ctx * context.Context ) string {
270
+ func transformedColumnsStr (dataStatuses map [string ]* resource.DataStatus , ctx * context.Context , showTitle bool ) string {
244
271
if len (ctx .TransformedColumns ) == 0 {
245
272
return ""
246
273
}
@@ -249,10 +276,15 @@ func transformedColumnsStr(dataStatuses map[string]*resource.DataStatus, ctx *co
249
276
for name , transformedColumn := range ctx .TransformedColumns {
250
277
strings [name ] = dataResourceRow (name , transformedColumn , dataStatuses )
251
278
}
252
- return titleStr ("Transformed Columns" ) + dataResourcesHeader () + strMapToStr (strings )
279
+
280
+ title := "\n "
281
+ if showTitle {
282
+ title = titleStr ("Transformed Columns" )
283
+ }
284
+ return title + dataResourcesHeader () + strMapToStr (strings )
253
285
}
254
286
255
- func trainingDataStr (dataStatuses map [string ]* resource.DataStatus , ctx * context.Context ) string {
287
+ func trainingDataStr (dataStatuses map [string ]* resource.DataStatus , ctx * context.Context , showTitle bool ) string {
256
288
if len (ctx .Models ) == 0 {
257
289
return ""
258
290
}
@@ -262,10 +294,15 @@ func trainingDataStr(dataStatuses map[string]*resource.DataStatus, ctx *context.
262
294
name := model .Dataset .Name
263
295
strings [name ] = dataResourceRow (name , model .Dataset , dataStatuses )
264
296
}
265
- return titleStr ("Training Datasets" ) + dataResourcesHeader () + strMapToStr (strings )
297
+
298
+ title := "\n "
299
+ if showTitle {
300
+ title = titleStr ("Training Datasets" )
301
+ }
302
+ return title + dataResourcesHeader () + strMapToStr (strings )
266
303
}
267
304
268
- func modelsStr (dataStatuses map [string ]* resource.DataStatus , ctx * context.Context ) string {
305
+ func modelsStr (dataStatuses map [string ]* resource.DataStatus , ctx * context.Context , showTitle bool ) string {
269
306
if len (ctx .Models ) == 0 {
270
307
return ""
271
308
}
@@ -274,10 +311,15 @@ func modelsStr(dataStatuses map[string]*resource.DataStatus, ctx *context.Contex
274
311
for name , model := range ctx .Models {
275
312
strings [name ] = dataResourceRow (name , model , dataStatuses )
276
313
}
277
- return titleStr ("Models" ) + dataResourcesHeader () + strMapToStr (strings )
314
+
315
+ title := "\n "
316
+ if showTitle {
317
+ title = titleStr ("Models" )
318
+ }
319
+ return title + dataResourcesHeader () + strMapToStr (strings )
278
320
}
279
321
280
- func apisStr (apiGroupStatuses map [string ]* resource.APIGroupStatus ) string {
322
+ func apisStr (apiGroupStatuses map [string ]* resource.APIGroupStatus , showTitle bool ) string {
281
323
if len (apiGroupStatuses ) == 0 {
282
324
return ""
283
325
}
@@ -286,7 +328,12 @@ func apisStr(apiGroupStatuses map[string]*resource.APIGroupStatus) string {
286
328
for name , apiGroupStatus := range apiGroupStatuses {
287
329
strings [name ] = apiResourceRow (apiGroupStatus )
288
330
}
289
- return titleStr ("APIs" ) + apisHeader () + strMapToStr (strings )
331
+
332
+ title := "\n "
333
+ if showTitle {
334
+ title = titleStr ("APIs" )
335
+ }
336
+ return title + apisHeader () + strMapToStr (strings )
290
337
}
291
338
292
339
func describePythonPackage (name string , resourcesRes * schema.GetResourcesResponse ) (string , error ) {
0 commit comments