Skip to content

Commit 9fb414f

Browse files
Search object types done
1 parent bac7a22 commit 9fb414f

2 files changed

Lines changed: 31 additions & 2 deletions

File tree

plugin/commands/search/types.go

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
package search
22

33
import (
4-
"fmt"
4+
5+
"bytes"
6+
"strconv"
57
"github.com/spf13/cobra"
68

9+
"github.com/IBM-Cloud/ibm-cloud-cli-sdk/bluemix/terminal"
10+
711
. "github.ibm.com/SoftLayer/softlayer-cli/plugin/i18n"
812
"github.ibm.com/SoftLayer/softlayer-cli/plugin/managers"
913
"github.ibm.com/SoftLayer/softlayer-cli/plugin/metadata"
14+
"github.ibm.com/SoftLayer/softlayer-cli/plugin/utils"
1015

1116
)
1217

@@ -37,6 +42,24 @@ func NewSearchTypesCommand(sl *metadata.SoftlayerCommand) *SearchTypesCommand {
3742

3843
func (cmd *SearchTypesCommand) Run(args []string) error {
3944

40-
fmt.Printf("Search Types would go here\n")
45+
type_results, err := cmd.SearchManager.GetTypes()
46+
if err != nil {
47+
return err
48+
}
49+
outputFormat := cmd.GetOutputFlag()
50+
if outputFormat == "JSON" {
51+
return utils.PrintPrettyJSON(cmd.UI, type_results)
52+
}
53+
table := cmd.UI.Table([]string{T("Name"), T("Properties")})
54+
for _, search_type := range type_results {
55+
sub_buf := new(bytes.Buffer)
56+
sub_table := terminal.NewTable(sub_buf, []string{T("Property"), T("Sortable"), T("Type")})
57+
for _, t_prop := range search_type.Properties {
58+
sub_table.Add(*t_prop.Name, strconv.FormatBool(*t_prop.SortableFlag), *t_prop.Type)
59+
}
60+
sub_table.Print()
61+
table.Add(*search_type.Name, sub_buf.String())
62+
}
63+
table.Print()
4164
return nil
4265
}

plugin/managers/search.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
type SearchManager interface {
1010
AdvancedSearch(mask string, params string) ([]datatypes.Container_Search_Result, error)
11+
GetTypes() ([]datatypes.Container_Search_ObjectType, error)
1112
}
1213

1314
type searchManager struct {
@@ -29,3 +30,8 @@ func (s searchManager) AdvancedSearch(mask string, params string) ([]datatypes.C
2930

3031
return s.SearchService.Mask(mask).AdvancedSearch(&params)
3132
}
33+
34+
35+
func (s searchManager) GetTypes() ([]datatypes.Container_Search_ObjectType, error) {
36+
return s.SearchService.GetObjectTypes()
37+
}

0 commit comments

Comments
 (0)