@@ -29,6 +29,7 @@ import (
2929 "github.com/cortexlabs/cortex/pkg/lib/json"
3030 "github.com/cortexlabs/cortex/pkg/lib/msgpack"
3131 "github.com/cortexlabs/cortex/pkg/lib/sets/strset"
32+ "github.com/cortexlabs/cortex/pkg/lib/slices"
3233 s "github.com/cortexlabs/cortex/pkg/lib/strings"
3334 libtime "github.com/cortexlabs/cortex/pkg/lib/time"
3435 "github.com/cortexlabs/cortex/pkg/lib/urls"
@@ -153,19 +154,19 @@ func resourceByNameStr(resourceName string, resourcesRes *schema.GetResourcesRes
153154func resourcesByTypeStr (resourceType resource.Type , resourcesRes * schema.GetResourcesResponse ) (string , error ) {
154155 switch resourceType {
155156 case resource .PythonPackageType :
156- return " \n " + pythonPackagesStr (resourcesRes .DataStatuses , resourcesRes .Context ), nil
157+ return pythonPackagesStr (resourcesRes .DataStatuses , resourcesRes .Context , false ), nil
157158 case resource .RawColumnType :
158- return " \n " + rawColumnsStr (resourcesRes .DataStatuses , resourcesRes .Context ), nil
159+ return rawColumnsStr (resourcesRes .DataStatuses , resourcesRes .Context , false ), nil
159160 case resource .AggregateType :
160- return " \n " + aggregatesStr (resourcesRes .DataStatuses , resourcesRes .Context ), nil
161+ return aggregatesStr (resourcesRes .DataStatuses , resourcesRes .Context , false ), nil
161162 case resource .TransformedColumnType :
162- return " \n " + transformedColumnsStr (resourcesRes .DataStatuses , resourcesRes .Context ), nil
163+ return transformedColumnsStr (resourcesRes .DataStatuses , resourcesRes .Context , false ), nil
163164 case resource .TrainingDatasetType :
164- return " \n " + trainingDataStr (resourcesRes .DataStatuses , resourcesRes .Context ), nil
165+ return trainingDataStr (resourcesRes .DataStatuses , resourcesRes .Context , false ), nil
165166 case resource .ModelType :
166- return " \n " + modelsStr (resourcesRes .DataStatuses , resourcesRes .Context ), nil
167+ return modelsStr (resourcesRes .DataStatuses , resourcesRes .Context , false ), nil
167168 case resource .APIType :
168- return " \n " + apisStr (resourcesRes .APIGroupStatuses ), nil
169+ return apisStr (resourcesRes .APIGroupStatuses , false ), nil
169170 default :
170171 return "" , resource .ErrorInvalidType (resourceType .String ())
171172 }
@@ -193,18 +194,29 @@ func resourceByNameAndTypeStr(resourceName string, resourceType resource.Type, r
193194}
194195
195196func 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+
196208 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 )
204216 return out
205217}
206218
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 {
208220 if len (ctx .PythonPackages ) == 0 {
209221 return ""
210222 }
@@ -213,10 +225,15 @@ func pythonPackagesStr(dataStatuses map[string]*resource.DataStatus, ctx *contex
213225 for name , pythonPackage := range ctx .PythonPackages {
214226 strings [name ] = dataResourceRow (name , pythonPackage , dataStatuses )
215227 }
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 )
217234}
218235
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 {
220237 if len (ctx .RawColumns ) == 0 {
221238 return ""
222239 }
@@ -225,10 +242,15 @@ func rawColumnsStr(dataStatuses map[string]*resource.DataStatus, ctx *context.Co
225242 for name , rawColumn := range ctx .RawColumns {
226243 strings [name ] = dataResourceRow (name , rawColumn , dataStatuses )
227244 }
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 )
229251}
230252
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 {
232254 if len (ctx .Aggregates ) == 0 {
233255 return ""
234256 }
@@ -237,10 +259,15 @@ func aggregatesStr(dataStatuses map[string]*resource.DataStatus, ctx *context.Co
237259 for name , aggregate := range ctx .Aggregates {
238260 strings [name ] = dataResourceRow (name , aggregate , dataStatuses )
239261 }
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 )
241268}
242269
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 {
244271 if len (ctx .TransformedColumns ) == 0 {
245272 return ""
246273 }
@@ -249,10 +276,15 @@ func transformedColumnsStr(dataStatuses map[string]*resource.DataStatus, ctx *co
249276 for name , transformedColumn := range ctx .TransformedColumns {
250277 strings [name ] = dataResourceRow (name , transformedColumn , dataStatuses )
251278 }
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 )
253285}
254286
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 {
256288 if len (ctx .Models ) == 0 {
257289 return ""
258290 }
@@ -262,10 +294,15 @@ func trainingDataStr(dataStatuses map[string]*resource.DataStatus, ctx *context.
262294 name := model .Dataset .Name
263295 strings [name ] = dataResourceRow (name , model .Dataset , dataStatuses )
264296 }
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 )
266303}
267304
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 {
269306 if len (ctx .Models ) == 0 {
270307 return ""
271308 }
@@ -274,10 +311,15 @@ func modelsStr(dataStatuses map[string]*resource.DataStatus, ctx *context.Contex
274311 for name , model := range ctx .Models {
275312 strings [name ] = dataResourceRow (name , model , dataStatuses )
276313 }
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 )
278320}
279321
280- func apisStr (apiGroupStatuses map [string ]* resource.APIGroupStatus ) string {
322+ func apisStr (apiGroupStatuses map [string ]* resource.APIGroupStatus , showTitle bool ) string {
281323 if len (apiGroupStatuses ) == 0 {
282324 return ""
283325 }
@@ -286,7 +328,12 @@ func apisStr(apiGroupStatuses map[string]*resource.APIGroupStatus) string {
286328 for name , apiGroupStatus := range apiGroupStatuses {
287329 strings [name ] = apiResourceRow (apiGroupStatus )
288330 }
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 )
290337}
291338
292339func describePythonPackage (name string , resourcesRes * schema.GetResourcesResponse ) (string , error ) {
0 commit comments