@@ -94,10 +94,22 @@ func printResource(result interface{}, format OutputFormat) error {
94
94
return nil
95
95
}
96
96
97
+ func isGateway (kind schema.Kind ) bool {
98
+ _ , isGatewayKind := kind .GetLatestKindVersion ().(* schema.GatewayKindVersion )
99
+ return isGatewayKind
100
+ }
101
+
102
+ func isConsole (kind schema.Kind ) bool {
103
+ _ , isConsoleKind := kind .GetLatestKindVersion ().(* schema.ConsoleKindVersion )
104
+ return isConsoleKind
105
+ }
106
+
97
107
func initGet (kinds schema.KindCatalog ) {
98
108
rootCmd .AddCommand (getCmd )
99
109
var format OutputFormat = YAML
100
110
111
+ var onlyGateway * bool
112
+ var onlyConsole * bool
101
113
var allCmd = & cobra.Command {
102
114
Use : "all" ,
103
115
Short : "Get all global resources" ,
@@ -106,23 +118,35 @@ func initGet(kinds schema.KindCatalog) {
106
118
var allResources []resource.Resource
107
119
108
120
kindsByName := sortedKeys (kinds )
121
+ if gatewayApiClientError != nil {
122
+ if * debug || * onlyGateway {
123
+ fmt .Fprintf (os .Stderr , "Cannot create Gateway client: %s\n " , gatewayApiClientError )
124
+ }
125
+ }
126
+ if consoleApiClientError != nil {
127
+ if * debug || * onlyConsole {
128
+ fmt .Fprintf (os .Stderr , "Cannot create Console client: %s\n " , consoleApiClientError )
109
129
130
+ }
131
+ }
110
132
for _ , key := range kindsByName {
111
133
kind := kinds [key ]
112
-
113
- // keep only the Kinds where kind.GetParentFlag() is empty and not of GatewayKind (demands extra configuration, TODO fix if config is provided)
114
- if len (kind .GetParentFlag ())+ len (kind .GetParentQueryFlag ()) > 0 {
134
+ // keep only the Kinds where listing is provided TODO fix if config is provided
135
+ if ! kind .IsRootKind () {
115
136
continue
116
137
}
117
- if _ , isGatewayKind := kind .GetLatestKindVersion ().(* schema.GatewayKindVersion ); isGatewayKind {
118
- continue
138
+ var resources []resource.Resource
139
+ var err error
140
+ if isGateway (kind ) && ! * onlyConsole && gatewayApiClientError == nil {
141
+ resources , err = gatewayApiClient ().Get (& kind , []string {}, []string {}, map [string ]string {})
142
+ } else if isConsole (kind ) && ! * onlyGateway && consoleApiClientError == nil {
143
+ resources , err = consoleApiClient ().Get (& kind , []string {}, []string {}, map [string ]string {})
119
144
}
120
-
121
- resources , err := consoleApiClient ().Get (& kind , []string {}, []string {}, map [string ]string {})
122
145
if err != nil {
123
146
fmt .Fprintf (os .Stderr , "Error fetching resource %s: %s\n " , kind .GetName (), err )
124
147
continue
125
148
}
149
+
126
150
allResources = append (allResources , resources ... )
127
151
}
128
152
err := printResource (allResources , format )
@@ -132,6 +156,9 @@ func initGet(kinds schema.KindCatalog) {
132
156
}
133
157
},
134
158
}
159
+ onlyGateway = allCmd .Flags ().BoolP ("gateway" , "g" , false , "Only show gateway resources" )
160
+ onlyConsole = allCmd .Flags ().BoolP ("console" , "c" , false , "Only show console resources" )
161
+ allCmd .MarkFlagsMutuallyExclusive ("gateway" , "console" )
135
162
allCmd .Flags ().VarP (enumflag .New (& format , "output" , OutputFormatIds , enumflag .EnumCaseInsensitive ), "output" , "o" , "Output format. One of: json|yaml|name" )
136
163
getCmd .AddCommand (allCmd )
137
164
0 commit comments