|
1 | 1 | package list |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "os" |
5 | 4 | "context" |
6 | 5 | "encoding/json" |
7 | 6 | "fmt" |
| 7 | + "os" |
8 | 8 |
|
9 | 9 | "github.com/antihax/optional" |
10 | 10 | "github.com/bf2fc6cc711aee1a0c2a/cli/cmd/rhmas/flags" |
11 | | - "github.com/bf2fc6cc711aee1a0c2a/cli/pkg/kafka" |
12 | 11 | "github.com/bf2fc6cc711aee1a0c2a/cli/pkg/api/rhmas" |
| 12 | + "github.com/bf2fc6cc711aee1a0c2a/cli/pkg/kafka" |
13 | 13 | "github.com/spf13/cobra" |
14 | 14 |
|
15 | 15 | mas "github.com/bf2fc6cc711aee1a0c2a/cli/client/mas" |
@@ -44,28 +44,32 @@ func runList(cmd *cobra.Command, _ []string) { |
44 | 44 |
|
45 | 45 | client := rhmas.BuildClient() |
46 | 46 | options := mas.ApiManagedServicesApiV1KafkasGetOpts{Page: optional.NewString(page), Size: optional.NewString(size)} |
47 | | - response, status, err := client.DefaultApi.ApiManagedServicesApiV1KafkasGet(context.Background(), &options) |
| 47 | + response, _, err := client.DefaultApi.ApiManagedServicesApiV1KafkasGet(context.Background(), &options) |
48 | 48 |
|
49 | 49 | if err != nil { |
50 | | - fmt.Fprintf(os.Stderr, "Error retrieving Kafka clusters: %v", err) |
| 50 | + fmt.Fprintf(os.Stderr, "Error retrieving Kafka clusters: %v\n", err) |
| 51 | + os.Exit(1) |
| 52 | + } |
| 53 | + |
| 54 | + if response.Size == 0 { |
| 55 | + fmt.Fprintln(os.Stderr, "No Kafka clusters found.") |
51 | 56 | return |
52 | 57 | } |
53 | 58 |
|
54 | | - if status.StatusCode == 200 { |
55 | | - jsonResponse, _ := json.Marshal(response) |
56 | | - |
57 | | - var kafkaList kafka.ClusterList |
58 | | - if err = json.Unmarshal(jsonResponse, &kafkaList); err != nil { |
59 | | - fmt.Fprintf(os.Stderr, "Could not format Kakfa cluster to table: %v", err) |
60 | | - outputFormat = "json" |
61 | | - } |
62 | | - |
63 | | - switch outputFormat { |
64 | | - case "json": |
65 | | - data, _ := json.MarshalIndent(kafkaList.Items, "", " ") |
66 | | - fmt.Print(string(data)) |
67 | | - default: |
68 | | - kafka.PrintToTable(kafkaList.Items) |
69 | | - } |
| 59 | + jsonResponse, _ := json.Marshal(response) |
| 60 | + |
| 61 | + var kafkaList kafka.ClusterList |
| 62 | + |
| 63 | + if err = json.Unmarshal(jsonResponse, &kafkaList); err != nil { |
| 64 | + fmt.Fprintf(os.Stderr, "Could not unmarshal Kakfa items into table: %v", err) |
| 65 | + outputFormat = "json" |
| 66 | + } |
| 67 | + |
| 68 | + switch outputFormat { |
| 69 | + case "json": |
| 70 | + data, _ := json.MarshalIndent(kafkaList.Items, "", " ") |
| 71 | + fmt.Print(string(data)) |
| 72 | + default: |
| 73 | + kafka.PrintToTable(kafkaList.Items) |
70 | 74 | } |
71 | 75 | } |
0 commit comments