File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package search
22
33import (
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
3843func (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}
Original file line number Diff line number Diff line change 88
99type SearchManager interface {
1010 AdvancedSearch (mask string , params string ) ([]datatypes.Container_Search_Result , error )
11+ GetTypes () ([]datatypes.Container_Search_ObjectType , error )
1112}
1213
1314type 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+ }
You can’t perform that action at this time.
0 commit comments